I am trying to create some columns using the autoHeight property set to true. However, I keep getting these warnings:
ag-grid: invalid colDef property 'autoHeight' did you mean any of these: suppressAutoSize,headerTooltip,openByDefault,headerComponent,suppressSizeToFit,sort,headerGroupComponent,pivot
<...snip...>
ag-grid: to see all the valid colDef properties please check: https://www.ag-grid.com/javascript-grid-column-properties/
My column definitions look something like this:
const columnDefs = [
{
headerName: 'Id',
field: 'id',
filter: 'agTextColumnFilter',
width: 90
}, {
headerName: 'Description',
field: 'sportLeage',
filter: 'agTextColumnFilter',
autoHeight: true,
valueGetter: params =>
params.context.liveEventsController
.createDescription(params.data),
width: 90
};
autoHeight is clearly listed as a valid column definition property. Though, in the debugger, I am looking at colDefUtil_1.ColDefUtil.ALL_PROPERTIES and autoHeight is not one of the available properties.
I am using ag-grid-enterprise v17.0.0.
My thinking is that either my version is out of date or the documentation is.
Check ag-grid v17.0.0 type definition code for ColDef here
autoHeight is not a property of ColDef.
I am currently at v17.1.1 and autoHeight is declared as number.
/** True if this column should stretch rows height to fit contents */
autoHeight?: number;
PS: The comments suggests that it should be a boolean.
Now this reminds me of a saying :)
Code never tells a lie, comments however, sometimes do.
Related
Setup Summary: We have two aggrids where we drag from one grid to the second grid. This works perfectly.
Issue: We have some lines we don't want to enable drag on. So we want a conditional drag based on a cell value.
Currently our table settings (we use reactjs) are as follows:
Table 1 and 2 have these properties:
rowData={rowData}
ref={fileGridRef}
columnDefs={columnDefs}
gridOptions={gridOptions}
rowDragManaged={true}
rowDragEntireRow={true}
animateRows={true}
onRowDragEnd={(params: any) => addToFilesGrid(params)}
suppressClickEdit={true}
gridOptions are (for both grids)
rowSelection: "single",
rowMultiSelectWithClick: true,
Column defs are (for both grids)
{
field: "name",
headerName: "File Name",
sortable: true,
filter: true,
editable: true,
cellStyle: { textAlign: "center", marginLeft: "-10px" },
cellRenderer: EditCellRenderer,
rowDrag: (params: any) => {
params.data.type !== ""; //HERE IS THE CONDITION WE HAVE
},
},
{
field: "type",
headerName: "Type",
sortable: true,
filter: true,
editable: false,
}
When the params.data.type is "" we want it not to move.
I tried playing around with rowDragManaged=false, but then nothing moved. I thought about making handlers for onDragEnter/Leave/Move/End, but I would rather avoid that if I can.
Anyone know what the issue is?
Do I have to do unmanaged dragging if I want this to work?
Finally found a solution!
I had seen that rowDrag could be set to a conditional statement but had issues getting it working, and there is one example on ag-grid docs that wasn't helpful in my use case.
So, I have a table, and if a cell is BLANK I don't want the row to drag.
So in the ColDef I had:
rowDrag: params => params.data.type === "",
Because that is what it was in the rowData. Also when I printed out params in other row changing functions (onRowSelected, onRowDragMove, etc...) this field was an empty string -> "".
It seems like for this conditional however it may be treated as an undefined or have a space. Not exactly sure, but I was able to do this:
params => params.data.type.length > 1,
And it worked! This leads me to believe the tags in the aggrid cell or something in their code inserts a space somewhere.
This was shown when I tried
rowDrag: params => params.data.type.length > 0,
and I could still drag the rows where my type field was "".
I tried removing the default filter of ag-grid which hides the column(s) and appears in the most right side of each column header, but I couldn't find the property. Can anyone help me?
You should use menuTabs property in column definition like this -
{
headerName: "Athlete",
field: "athlete",
width: 150,
filter: "agSetColumnFilter",
menuTabs: [ 'filterMenuTab', 'generalMenuTab']
}
As per docs -
menuTabs Set to an array containing zero, one or many of the
following options 'filterMenuTab', 'generalMenuTab' and
'columnsMenuTab'. This is used to figure out which menu tabs and in
which order the tabs are shown
We'd like to use React Data Grid from Adazzle (as mentioned in the tag with this question) now that we're using React (16.xx) and the older jsGrid is less appealing.
Two questions:
Our old jsGrid had a data type to include in the grid called Checkbox. This was immensely helpful. I haven't found a similar type in the React Grid. Have I just missed it or is it not a part of the library?
In each row, in some columns, we'd like to actually have two rows of data inside the column -- i.e., two lines of text separated by carriage return. But the react-data-grid demos only seem to show one line per column. Is this a limitation, or can we use CSS in the values inside columns?
Is there search included for the rows shown in the table at any given point in time?
I will provide answer to your question part by part
1) In react-data-grid column you can include a checkbox by using the formatter
attribute that is specified while the columns are defined.
Consider the following example
let columns = [
{
key: 'name',
name: 'Name',
resizable: true,
width: 100
},
{
key: 'checkbox',
name: 'CheckBox',
formatter:checkBoxFormatter,
resizable: true,
width: 100
}
]
class checkBoxFormatter extends React.Component {
render() {
return (
<div>
<CheckBox></Checkbox> //Provide your checkbox code here
</div>
)
}
}
2)You can exapand the rows for that you need to use getSubRowDetails and onCellExpand attributes of ReactDataGrid component .For example refer this documentation
3)Search is available for filtering .For example refer this documentation
Is there something else I need to do to ensure gridOptions.columnApi.setColumnVisible does what it says on the tin? :-
This code is running at runtime on a rendered grid and should just hide the column instantly, but does nothing:-
gridOptions.columnApi.setColumnVisible("the col name", false);
Two possible causes of this:
The grid isn't ready when you attempt to hide the column. This probably isn't the case as you say the grid has been rendered, but it's worth checking
You're not using correct column identifier. This can be either a column id or Column object.
It's probably the latter - are you perhaps using the header name instead of the field/col id?
For example, if you have this:
var columnDefs = [
{headerName: "Athlete", field: "athlete", width: 200}
];
Then the first parameter would be 'athlete', not 'Athlete'.
You can additionally specify a colId to rule out any conflicts and then use this id in your api call:
var columnDefs = [
{headerName: "Athlete", field: "athlete", width: 200, colId: "athleteCol"}
];
But this isn't normally necessary.
In case this helps someone else - I was having a similar problem, but with the actual column method itself. So for my application at least, the setVisible method of the column doesn't work correctly, but the setColumnVisible method of the columnApi method does work:
// does NOT work correctly
this.columnApi.getColumn('name').setVisible(true);
// does work correctly
this.columnApi.setColumnVisible('name', true);
Referring to the Aurelia ag-grid example code:
I am hiding Columns at runtime as follows in the *.ts component's constructor:
this.gridOptions.onGridReady = () => {
...snip
this.columnApi = that.gridOptions.columnApi;
this.gridOptions.columnApi.setColumnVisible('REQCONTEXT', false);
}//onGridReady
Where 'REQCONTEXT' is the name of the columns to hide.
I've had the exact problem, solved by adding
setTimeout(() => {
this.grid.api.refreshView();
this.grid.api.sizeColumnsToFit();
}, 0)
after calling setColumnVisible
Make sure you got
(gridReady)="onGridReady($event)"
in the template.
I do that all the time!
Cheers!
I have requirement to get a drop down from a column which should have three values. I marked the column as editable with editable: true keyword, even then I am not able to edit. I just need a drop down with two values when i double click on the cell.
{headerName: "O", width: 70, valueGetter: this.geValue, editable: true, cellEditor: 'select',
cellEditorParams: {
values: ['Yes', 'No']}
}
I am using select here but not rick select because i am not using ag-grid enterprise. I am also setting these below properties for all the rows.
suppressCellSelection: true,
suppressMovableColumns: true,
suppressRowClickSelection: false,
I need help to find if I am missing anything here. I am not getting a drop down when I double click on cell.
I could finally figure out why I could not edit the cell even if I declare it editable. Because css is adding a class as shown below
<div class="ag-cell-no-focus ag-cell ag-group-cell ag-cell-not-inline-editing ag-cell-value" colid="O" style="width: 54px; left: 48px;"></div>
I have to remove ag-cell-not-inline editing class from the div. I am not sure how. Is there any option to remove default class from grid options?