Using answer from Set rownumbers to false dynamically in jqgrid I created row numbers toggle button.
Initially row numbers are not shown. Button click is ignored, row numbers column is not added.
How to force button to add row number column ?
Or is it possible to add option to column chooser to toggle row number columns ? This would be better, not additional button is required.
var rownumbers= isColState ? myColumnsState.rownumbers : false;
$("#grid_toppager_left table.navtable tbody tr").append(
'<td class="ui-pg-button ui-corner-all">' +
'<div class="ui-pg-div my-nav-checkbox">' +
'<input tabindex="-1" type="checkbox" id="RowNumbers" ' + (rownumbers ? 'checked ' : '')+'/>' +
'<label title="Toggle row numbers"' +
' for="RowNumbers">Toggle row numbers</label></div></td>'
);
$("#RowNumbers").button({
text: false,
icons: {primary: "ui-icon-grip-dotted-vertical"}
}).click(function () {
rownumbers = !rownumbers;
if (rownumbers ) {
$grid.jqGrid('showCol', 'rn');
} else {
$grid.jqGrid('hideCol', 'rn');
}
saveWindowState();
});
Update
jqgrid contains also multiselect and _actions columns. in loadcomplete new row is added to end of grid using
var newRowData = { Dokumnr: 123,
Reanr: $grid[0].rows.length + 1
},
newRowId = '_empty' + $.jgrid.randId();
$grid.jqGrid('addRowData', newRowId, newRowData);
If row numbers are turned on in first time after load, multiselect column checkbox in added row appears in rown numbers column:

How to fix this ?
You have to include
rownumbers: truein any way to create the row numbers. If you want that row numbers are initially not shown you should call$grid.jqGrid('hideCol', 'rn');after the grid is created. You can additionally setrownumbersto false with respect of$grid.jqGrid('setGridParam', {rownumbers: false});, but I don’t think that it’s really required.After that you can use the button
$("#RowNumbers")like you as wanted initially. Probably you can consider to setrownumbersoption totrueorfalsetogether withshowColandhideColand use therownumbersoption instead of yourrownumbersvariable.UPDATED: The current code of
addRowDatajust test whetherrownumbersoption of jqGrid istrue:Depend on the value it calculate the position of the data:
So I should correct my answer. You should not change the value of
rownumbersoption. It should stay alwaystrueeven if the corresponding column will be hidden.