I am using React Ag-grid version 25.3.0. I need to autoSizeAllColumns everytime the grid data is updated. I have tried onRowDataChanged. But, this is fired before the custom cellRenderers complete the rendering. So, I am looking for an Grid Event or callback where I get notified once all the rendering is complete. Below is the sample snippet,
<AgGridReact
frameworkComponents={{
renderer: CustomRenderer,
}}
columnDefs={columns}
rowData={rowData}
OnRowDataChanged={(event) => event.columnApi.autoSizeAllColumns()} //this doesn't wait for frameworkComponents
/>
The autoSizeAllColumns would work if I add a delay to it by doing something like this.
OnRowDataChanged={(event) => setTimeout(() => event.columnApi.autoSizeAllColumns(), 300}
But this doesn't look clean and looks somewhat ugly in the UI as the updates and autoSize happen with a delay. What's the best way to handle such scenarios.
I have resizable: true in the columnDef. The autoSizeAllColumns() works just fine for plain columns. But only doesn't work for columns with cellRenderer
const columnDefs = [
{ field: 'name', resizable: true, cellRenderer: 'renderer' },
{ field: 'age', resizable: true },
{ field: 'address', resizable: true },
];
In the above sample, autoSizeAllColumns() with onRowDataChanged event would work fine for columns 'age' and 'address', but not for 'name'.
Help please :-)
Related
We are using "ag-grid-community": "26.2.0" and "ag-grid-react": "26.2.0" packages in our project. We have implemented a wrapper reusable component which we're planning to use across the application.
The requirement states that checkbox selection and the first column are to be pinned to the left by default.
Column Definitions:
const colDefs = [
{
headerName: "Vulnerability Title",
field: "patchName",
cellRendererFramework: patchListRenderers.patchNameRenderer,
pinned: "left", // pinned property
minWidth: 300,
},
{
headerName: "Status",
field: "vulnerabilityStatus",
minWidth: 180,
},
{
headerName: "Vulnerability ID",
field: "cveId",
minWidth: 210,
},
// more column definitions here
]
My gridOptions are this:
export const gridProps = {
reactUi: true,
rowHeight: 70,
headerHeight: 70,
rowSelection: "multiple",
suppressRowClickSelection: true,
pagination: true,
paginationPageSize: 10,
suppressPaginationPanel: true,
enableCellTextSelection: true,
ensureDomOrder: true,
suppressDragLeaveHidesColumns: true,
suppressColumnVirtualisation: true,
popupParent: document.querySelector("body"),
};
I am facing a weird issue where the pinned column headers are shown, but the data underneath is missing, however, once I drag around the pinned column a bit, everything comes back in its proper place. Please refer to the GIFs attached.
Things I've tried:
Changed the width values,
Tried true and false for suppressColumnVirtualisation property.
Tried to use gridApi.redrawRows() and gridApi.refreshCells() on the onGridReady event.
None of these suggestions worked.
GIF 1
GIF 2
I use 3 stateful grids that are replaced between each other in the same view. 2 of those grids simply extends first one. The only difference between grids is initial visibility of some columns. User can change this visibility in column menu and this setting stay like that because of stateful config.
Everything works good, when we consider only stateful part. But I don't know how to set initial visibility of columns. I tried like that
initComponent: function () {
this.columnManager.getHeaderByDataIndex('firstIndex').setHidden(true);
this.columnManager.getHeaderByDataIndex('secondIndex').setHidden(true);
}
and it works, columns are hidden when grid is opened for the first time and visible when user changes something and then open application once more. There is only 1 problem - in column menu they are always indicated as hidden which is clearly taken from my initComponent function. So I thought that maybe there is a way to check if grid has been ever shown or not. something like:
initComponent: function () {
if (!this.getState()) {
//hide given columns here
}
}
but it doesn't work too, as state is always null.
Why don't you do it in column config of the grid? Something like
Ext.create('Ext.grid.Panel', {
title: 'Simpsons',
store: Ext.data.StoreManager.lookup('simpsonsStore'),
columns: [{
text: 'Name',
dataIndex: 'name'
}, {
text: 'Email',
dataIndex: 'email',
flex: 1
}, {
text: 'Phone',
dataIndex: 'phone',
hidden: true // <--- HERE
}]
});
I have a renderer set up on my Sencha Ext.JS 3.4 EditorGridPanel. I allow the user to click a button, add rows and fill in various cells in those rows, and I set up a cue banner to show some useful text as soon as a blank row is added.
My cue banner solution is based on another SO answer, and the solution works great except for one small caveat: when someone types in text in one of the cells and later reverts that text to blank, whatever was there before is kept instead of becoming blank. You can edit to your heart's content, but as soon as you try to delete all text in a cell, your changes are ignored.
I've looked through the Sencha docs on the renderer and the onblur and even the listener parameters, and I've tried trapping the onblur event, but no events seem to even fire (using Chrome developer tools breakpoints). Is there a way to get this to work so that someone can revert the text to blank once they've typed?
Some Relevant Code:
(per comment request)
function renderCueBanner( value, metaData, record, rowIndex, colIndex, store ) {
if( !value && record.phantom )
return 'Double-click, and type';
else
return value;
}
//other code
MyCompany.ui.grid.Macros = Ext.extend(Ext.grid.EditorGridPanel, {
title: 'Macros',
//other code
var config = {
stripeRows: true,
viewConfig: { emptyText: 'No Macros to display' },
loadMask: true,
store: store,
sm: sm,
tbar: tbar,
colModel: new Ext.grid.ColumnModel({
defaults: {
menuDisabled: true
},
columns: [sm, {
header: 'Macro Category',
dataIndex: 'group',
sortable: true,
editor: {
fieldLabel: 'Macro Category',
forceSelection: false,
typeAhead: false,
valueField: 'name',
xtype : 'MyCompany.ui.autocompleter.MacroGroup'
},
renderer : renderCueBanner,
width: 150
}, {
header: 'To',
dataIndex: 'to',
editor: {
xtype: 'textfield',
allowBlank: false
},
sortable: true,
renderer : renderCueBanner,
width: 400
}],
listeners: {
'onblur' : {
fn: renderCueBanner,
handler: renderCueBanner,
delay: 100
}
},
isCellEditable: function(col, row) {
if (!Lynx.userCan('write')) {
Ext.Msg.alert(
'Access Denied',
'You are a read only user'
);
return false;
}
return Ext.grid.ColumnModel.prototype.isCellEditable.call(this, col, row);
}
}),
//...other code...
};
The problem is most likely caused by allowBlank:false in combination with the default value of revertInvalid:true.
The behavior is as expected in fact: You do not allow the field to stay blank so the editor reverts to the last valid, non-blank value.
Try to add revertInvalid:false or remove allowBlank:false (preferred) and it should work.
I have the following code which works on all browsers except Firefox:
{
xtype: 'gridcolumn',
dataIndex: 'action',
flex: 1,
text: 'Action',
editor: new Ext.form.field.ComboBox({
typeAhead: true,
triggerAction: 'all',
selectOnTab: true,
store: [
['Update','Update'],
['Suspend','Suspend'],
['Cancel','Cancel']
],
lazyRender: true,
listClass: 'x-combo-list-small',
listeners: {
change:{
scope: me,
fn: me.processAction
},
focus: function(combo) {
combo.expand();
},
collapse: function(combo) {
//combo.setVisible(false);
}
}
})
}
The problem is that when you click on the combo box, the first item in the list is <div id="ext-gen1584" class="x-grid-cell-inner " style="text-align: left; ;"> </div>.
Has anyone else encountered this? Is it a bug in Ext or in Firefox?
Currently testing in Firefox 18.0.2.
I had this bug, like the others said, it happens when you haven't dataIndex's field in model. But here's one little moment, that you HAVE to initialize that field in model, even by empty value, and then it will render correct.
Yes, < 5.0 versions have bug in firefox - when dataIndex have invalid name, editor got wrong value.
Just look example
header: 'Relationship',
dataIndex: 'relationshipWRONG', // rename this on 'relationship'
flex: 2,
getEditor: function() {
return Ext.create('Ext.grid.CellEditor', {
field: Ext.create('Ext.form.field.ComboBox', {
store: relativeStore,
displayField: 'name',
valueField: 'name',
editable: false
})
});
}
Look at this in chrome and firefox, in firefox you see dom element instead null value. In 5 verion all is well.
Rename this dataindex and value will be correct.
But i seen this bug when dataIndex is correct on datacolumn, and i have not found how to resolve it and just changing value in beforestartedit event(ofc it's bad practise)
I have meet similar problem in grid,if the dataIndex have no value,then the cell will show what you have seen..so pls check the content of the dataIndex:Action;
Here is what I figured out today in my case...
In a scenario where you have
1 - a store with fields 'id', 'name', 'displayName' with a combo on displayName field.
in response to daixfnwpu: AND dataIndex is set for each field.
2 - a record to add with fields 'id', 'name' but NO displayName in it.
If you do a store.add(record), this seems to work and displayName will be set to an empty string ""
But if you drag-drop the record, the drop action does not seem to set the displayName and it stays undefined... This is a source of problems...
I fixed this by filtering the added records onDrop...
Ext.each(records, function(record) {
var displayName = record.get('displayName');
record.set('displayName', displayName ? displayName : '');
record.commit();
});
I am using Ext Js 4.1, and I need to put a comboBox in a grid cell to user choose the parameter that gonna be saved, however the available parameters coming from a store, but it does not working, I am already using editing plugin, as specified in docs, can anyone provide a insight ??
storeParameter = Ext.create('ParameterStore');
{
header: 'Parameter',
flex: 1,
sortable: true,
dataIndex: 'parameter',
field: {
type: 'textfield'
},
editor: {
xtype: 'combo',
store: storeParameter
}
},
you should define the editor parameter on the grid cell where you want it to appear. Seems like you are trying to defining the editor in the store itself.
I solved the problem. I needed to add the attribute in grid:
selType: 'cellmodel',
And instead of to put a store directly, I replaced for comboBox, which has the store.
var comboParameter = Ext.create('ComboBoxParameter');
And the column replace to:
{
header: 'Parameter',
flex: 1,
sortable: true,
dataIndex: 'parameter',
editor: comboParameter
},