Just to confirm I'm not insane--if the following works:
$( '#idGrid' ).igGrid( { ... features: [ { name: 'GroupBy', columnSettings: [ { columnKey: 'MpName', isGroupBy: true, dir: 'desc' } ] } ] });
$( '#idGrid' ).igGrid(
{
...
features: [
name: 'GroupBy',
columnSettings: [
columnKey: 'MpName',
isGroupBy: true,
dir: 'desc'
}
]
);
...then the following should be expected to work as well, right??
var columnSettingsGroupBy = [];...columnSettingsGroupBy.push( { columnKey: 'MpName', isGroupBy: true, dir: 'desc' } );
var columnSettingsGroupBy = [];
columnSettingsGroupBy.push( { columnKey: 'MpName', isGroupBy: true, dir: 'desc' } );
$( '#idGrid' ).igGrid( { ... features: [ { name: 'GroupBy', columnSettings: columnSettingsGroupBy } ] });
columnSettings: columnSettingsGroupBy
I have a loop iterating over column names and building my columnSettingsGroupBy array dynamically (pushing values into it based on settings saved in a file rather than being hardcoded), but ultimately the end result is the same. So if I can confirm that the above can be expected to work...I'll know the problem probably lies within my loop somewhere (even though by the time it's done, my array looks the same).
Hello dandy,
Thank you for posting in our forum.
Both of these snippets are valid, but it is recommended that the columnSettings array gets defined before you initialize and bind the grid.
Providing some of your code that reads the file, as well as this for-loop you mentioned would be appreciated and would allow me to give you a more detailed answer.
Also, do you have a requirement to modify the columnSettings array afterwards at runtime, or do you just want to construct it dynamically?
If you need any additional assistance, feel free to contact me.
Thanks for confirming. Indeed, I read my file and process its content (and build my array from it) before the grid is built - and then I don't need to touch that array ever again (in fact it would go out of scope once the function building the grid dynamically returns). If I need to make additional changes at runtime, but after the grid's already been initialized, I do it through the proper channels, such as:
$( '#idGrid' ).igGridGroupBy( 'groupByColumn', colName );
Here's more of what my initialization looks like. 'columns' is the column array I provide to the grid, and columnSettingsGroupBy is the array provided to the columnSettings property for GroupBy (as per my previous sample). As mentioned before, if the hardcoded line (currently commented out below) is used, the grouping is done - but when it goes through the loop, it's not. 'cfgObj' is an object representing the configuration options read from a file. As you can see, I'm also hiding columns at the same time (which works).
var columns = [ { headerText: 'col1', key: 'col1', dataType: 'string' }, { headerText: 'col2', key: 'col2', dataType: 'string' }, { headerText: 'col3', key: 'col3', dataType: 'string' },};
var columnSettingsGroupBy = [// { columnKey: 'col1', isGroupBy: true, dir: 'desc' }];
if ( cfgObj != null ){ for ( var c in columns ) { var colObj = columns[ c ]; ConsoleLog( 'Processing column with key ' + colObj.key ); if ( cfgObj.Hiding !== undefined ) { var oHidden = cfgObj.Hiding.find( o => o.key === colObj.key ); if ( oHidden !== undefined ) { colObj.hidden = oHidden.hidden == 1 ? true : false; } else { colObj.hidden = false; } } if ( cfgObj.Grouping !== undefined ) { var oGrouping = cfgObj.Grouping.find( o => o.key === colObj.key ); if ( oGrouping !== undefined ) { columnSettingsGroupBy.push( { columnKey: colObj.key, isGroupBy: true, dir: oGrouping.dir } ); ConsoleLog( 'Grouping column ' + oGrouping.key ); } else ConsoleLog( 'Could not find a grouping option for column ' + colObj.key ); } else ConsoleLog( 'No grouping option whatsoever' ); } ConsoleLog( columnSettingsGroupBy );}
Regardless of the method I use to initialize columnSettingsGroupBy, this is what Console.Log( columnSettingsGroupBy ) shows, just before handing it off to the grid initialization:
Because for all intents and purposes it's identical, this is why I get confused as to why the hardcoded array works, but not the one built from the loop.
Anyway, at this point it doesn't matter much, because I do have the option to call:
...after the grid's already been initialized - but I would think it best if the grouping was simply done as the grid is being initialized instead of waiting after it's been rendered already.