How to have a free width column based on the row width in the table? - css

and I have the following code:
return (
<Box sx={{ height: 400 }}>
<DataGrid columns={columns} rows={rows} />
</Box>
)
and I am having the table getting rendered as:
I want the column of the email to take the width of the widest row cell automatically, so I want the table to render as follows:
My colums and rows look simply as follows:
const columns = [ { field: "firstName" }, { field: "lastName" }, ...etc ]
const rows = [
{ firstName: "Camil Pasa Sokak", lastName: "In The Village", ...etc },
... etc
]
How to do it in MUI x (community table, the free one)?
I want the column of the email to take the width of the widest row cell automatically
please note: since the table is wide, it will automatically show you a scrollbar (x and y scrollbars). I want to keep this functionality, I want to keep these scrollbars (from the x and y) I don't want to disable them.
Here's a sandbox instnce:
https://codesandbox.io/s/strange-newton-z6pwj4?file=/src/App.js

Looking at the docs for the datatable component you are using, it's not super clear the best way to go about it. The crux of the problem is that this is a div + flexbox table and not a true html table. As such, cells within a single column are not really "bound" to each other the same way as a regular html table.
There is a page which addresses column dimensions, but I could not find a satisfactory solution there. I was particularly disappointed that maxWidth seems to do nothing. The closest I got was setting a fixed column width, but I don't think that's what you want:
const columns = [{
field: "email", width: 300,
}]
So then I moved on to their styling cells page, which allows you to have much more control over styling, but this still doesn't work because one flex cell does not affect the size of all flex cells in a column - each row has a different sized cell based on the size of the email address.
const columns = [{
field: "email", cellClassName: "foobar",
}]
<DataGrid columns={columns} rows={rows} sx={{
"& .foobar": {
maxWidth: "300px !important"
}
}} />
So, my best suggestion is to loop over the data, find the longest email address, and set the fixed width based on that. This kinda sucks, but I don't see another way to properly set dimensions for a flexbox-based table:
const longestEmail = rows.reduce((longest, row) => {
return row.email.length > longest.length ? row.email : longest
}, '');
const columns = [{
// play around with the multiplier until you find a suitable width
field: "email", width: longestEmail.length * 9,
}]

This is from the Documentation..Number Signature
<DataGrid
columns={[
{ field: 'username', colSpan: 2, hideable: false },
{
field: 'organization',
sortable: false,
filterable: false,
hideable: false,
},
{ field: 'age', hideable: false },
]}
rows={rows}
{...other}
/>
you can use colspan but it sets all cells in the column to span a given number of columns.
const columns = [{
field: "email",colSpan:2,
},]

Related

react-jsonschema-form collapses the size of my array form and cuts off buttons

I've started building a form in react-jsonschema-form and i'm having a lot of difficulty changing it visually.
The form is an array and it has a button to add and remove a set of input boxes.
I've build it as a component in a test project which has no css applied to it so far.
The form will render as a tiny box where there is no room for the buttons (they are cut of as shown below in images).
a single element
a second element
How its supposed to look on react-jsonschema-form playground
A key difference between my array and the sample array is that i'm having two text input elements per array element. I dont know if this could cause it.
I do need to have two input values as its a group of data that is related, and both is required.
This is my code:
//json schema
const schema = {
type: "object",
properties: {
listOfNumbers: {
title: "opret ledig nummerserie",
type: "array",
required: ["nr_fra", "nr_til"],
items: {
properties: {
nr_fra: {
type: "string",
pattern: "^\\d*$",
minLength: 8,
maxLength: 8,
},
nr_til: {
type: "string",
pattern: "^\\d*$",
minLength: 8,
maxLength: 8,
},
},
},
},
},
};
//uiSchema
const uiSchema = {
listOfNumbers: {
"ui:options": {
orderable: false,
},
items: {
//nr_fra: { "ui:options": { label: false } },
//nr_til: { "ui:options": { label: false } },
},
},
}
I'm applying no css to the below form.
// Form
<Form
schema={schema}
uiSchema={uiSchema}
formData={this.state.formData}
onSubmit={(formOutput) => this.handleSubmit(formOutput)}
transformErrors={transformErrors}
/>
I've spent a day and a half on trying to strongarm this, but i could really use some help on how to proceed.
It seems it was css inputs that was needed to solve this.
The below will expand the elements to their proper size/form.
Posting this here for posterity, as this is not accurately documented.
<div className="col-md-offset-3 col-md-6">
<Form schema={schema}
uiSchema={uiSchema}>
</Form>
</div>

Antd expandable table, expand all rows at same time when click on expand button

I'm using an expandable table from antd design version 4.10 in my app with Next.js v10.0.4. When I clicked in + button in table its suppose to open only the row which is selected but I don't know why it is opening all the rows at same time.
This is my table component:
<Table
size="small"
dataSource={data}
columns={updateColumns}
expandable={{
expandedRowRender: (record) => (
<p style={{ margin: 0 }}>{record.description}</p>
),
rowExpandable: (record) => record.level !== "3",
onExpand: (expanded, record) =>
console.log("onExpand: ", record, expanded),
}}
/>
Is exactly the same code as documentation in antd design: https://ant.design/components/table/#components-table-demo-expand
You need a key property for each record in your data. If you have no key property, you can specified it on <Table> component using rowKey prop
<Table rowKey="your_data_id" />
I had the same problem with the table, I issue is not the code but your data. For the table work you need to add a "key" to every set of json data that you are giving to the table .
Example:
[
{
"key": 1,
"name": "hello",
"surname": "world"
},
{
"key": 2,
"name": "hello",
"surname": "world"
}
]
This probably due to missing keys in your dataSource array which is fed into the Table, which can be verified by a message in the DevTools console saying smth about missing key.

grid.getColumnmanager().getColumns() is not giving parent column in Ext JS grid

I have grid having grouped columns.
Some of my code is as follows:
Ext.require([
'Ext.grid.*',
'Ext.ux.grid.FiltersFeature',
'Ext.ux.LiveSearchGridPanel'
...
]);
var filters = {
ftype: 'filters',
encode: false,
local: true
};
var grid = new Ext.create('Ext.ux.LiveSearchGridPanel', {
selType: 'cellmodel',
store: store,
columns:[
{
header: "Column1"
dataIndex: 'Column1'
},{
header: "Column2",
columns : [{
header: "innerColumn1",
dataIndex: 'innerColumn1'
},{
header: "innerColumn2"
dataIndex: 'innerColumn2'
}]
},{
header: "Column3",
dataIndex: 'Column3'
}],
features: [filters]
...
Now, if I use grid.columnManager.getColumns() it returns following columns:
Column1
innerColumn1
innerColumn2
Column3
It is not returning Column2 which is a parentColumn/groupColumn of innerColumn1 & innerColumn2. Which method of Ext Js I should use to get Column2 as well in the columnList? I am using Ext Js 4.2. Any help will be appreciated.
grid.getColumnmanager().getColumns() does not provide parent column of grouped columns. Column manager is to deal with only leaf columns.
While iterating columns you can access isSubHeader property only available in child groped columns and after that through ownerCt property you can access parent column.
hope this helps.
One of the solution to get all the columns is to make use of Ext ComponentQuery. I have created this fiddle. Look into the developer console of after running this fiddle.
So simplest query to get all the columns is :
grid.query('gridcolumn:not([hidden])')// Open fiddle for full example
It will simply return all visible columns. You can change query according to your requirements.
For Example, to get only the Grouped Column, you can use this
grid.query('gridcolumn[isGroupHeader=true]')
Click here for more information about ComponentQuery.

kendo ui multiple columns one

I'm using codeingniter, doctrine and KendoUI on a project and I've come across this problem:
in my DB I have 2 columns of a DB but I want to show them in only one column in the KendoUI grid, so far I've been able to show them, but when I try to create a new row or edit an existing one I can't because the in the template I created I don't know how to specify the fields so I can edit and create rows, I pasted a chunk of the code and if you see in the 4th column is the problem that I have.
Thanks in advance.
schema: {
model: {
id: "idAction",
fields: {
actionId: { editable: false },
strategy: {field:"strategy", type:"number"},
actionName: { validation: { required: true } },
actionDescription: { validation: { required: true }, type:"string" },
actionEstimatedTimeQuantity: {validation: {required:true}, type:"number"},
actionEstimatedTimeUnit: {validation:{required:true}},
actionEstimatedCost:{validation:{required:true},type:"number"},
actionCreatedBy: { editable:false },
actionCreatedDate: { editable:false, type:"date" }
}
}
}
And in my columns I have
columns: [
{
field: "strategy",
width: "180px",
title: "Estrategia a usar",
values: strategies
},
{
field: "actionName",
width: "100px",
title: "Accion"
},
{
field: "actionDescription",
width: "200px",
title: "DescripciĆ³n"
},
{
field: "actionEstimatedTimeQuantity - actionEstimatedTimeUnit"
template: "#= actionEstimatedTimeQuantity # - #= actionEstimatedTimeUnit #",
width: "150px",
title: "Tiempo Estimado"
},
{
field: "actionEstimatedCost",
width: "150px",
title: "Costo Estimado"
},
{
field: "actionCreatedBy",
width: "100px",
title: "Creada Por"
},
{
field: "actionCreatedDate",
width: "150px",
title: "Fecha de CreaciĆ³n",
format: "{0:MM/dd/yyyy}"
},
Try making a new object 'model' that represents your target data. Populate it and parse it in a controller using whatever logic you specify. Map this new model to your grid.
My team does this for every data element, essentially turning them into business objects, even if it is a direct 1 to 1 relationship.
I think you want to display two Numeric columns as a string combination "TimeQuantitiy - TimeUnit". In this case, better you add one more field of type string to the datasource of your kendo grid.
from Server: send one more column of type string "a-b"
at client: display it in grid.
Editing: You have two choices -
Use one textbox which accepts input string as "a-b"
Use two textboxes seperated with "-" (you might need to define a custom editor for you column in this case"
I would like to apologize for being more theoretical, I would try to upload some programming if possible.

Sencha EXT JS datagrid scrollbar specifically on column?

We have a gridpanel with columns, that are displaying fine. One column in particular, is a string that can be very large. We want to add a scrollbar to this one column only to accommodate the large wall of text.
Can this be done with Sencha EXT JS? Or if scrollbars can not be done, how about a mouse over to show the whole text in the column?
var secondTab = Ext.create('Ext.grid.Panel', {
columnWidth: 0.60,
xtype: 'gridpanel',
store: standardsResultsStore,
autoheight: true,
columns: [
{
id :'standardName',
text : 'Standard Name',
flex: 1,
sortable : true,
dataIndex: 'standard'
},
{
text : 'Description',
flex : 2,
sortable : true,
dataIndex: 'description_standard'
}
]
});
I did it with CSS, and added tdCls to the specific column
.custom-column .x-grid-cell-inner { white-space:normal; }
--- in tab tdCls: 'custom-column'

Resources