I have a jqgrid, on setting multicheck I am getting the checkbox on first column, I want that checkbox column to be the last column.
I found no option on it, so I am writing a custom jquery method to move the first td
of the tr
to last.
I am try using
loadcomplete:function{
var row = $(".cbox");
for (var i = 0; i < row.length; i++) {
var tr = $(row[i]).parent().parent().parent();
var td = $(row[i]).parent().parent();
var newtd = $(td).clone(true);
$(tr).append($(newtd));
$(tr).remove($(td)); // i am getting exception here
}
}
Please help.
Any reason why that's so complex? This should do it:
Live example: http://jsfiddle.net/QEuxN/1/
I find you question interesting, but the answer is not so easy. The problem is that jqGrid use the index of
colModel
column in some places to find the column value. So if one just move<td>
elements inside of every row of the grid you will have correct information displayed in the grid, but the grid will be not editable. No editing mode will work with the grid.Next problem. In the your example you used
'td:first'
to get the cell with the checkbox. It will be wrong in case of usage ofrownumbers: true
option. In the case the checkbox will be in the second and not the first column.The most good way to reorder the columns together with
colModel
will be the usage ofremapColumns
method likeIt you look at the demo which use this you will see that everything is correct at the first time, but after changing the page, sorting a column or any other refreshing of the grid the grid will be wrong filled. The reason of the problem is that the current code of jqGrid works only if the column with multiselect-checkboxes is one from the first grid columns. Look at the code fragment for example:
The usage
gi+si+ni
in the index ofcolModel
array will not work after reordering ofcolModel
. There are other places of code inside ofaddXmlData
,addJSONData
,addRowData
ofgrid.base.js
. So to have full support of the multiselect-checkboxes one have to make changes in all the functions.If you need only display the data in the grid without editing I can suggest you solution which looks to work good. See the demo. Before posting any code I explain you what should be done in the code.
The body of grid has always one hidden row (
tr.jqgfirstrow
) which will be used to set the column width. One should change the order in the columns in the row once time. Additionally one have to change the order of columns in the column headers (including the searching toolbar if it exists) and the footer (summary) row if any exist.All other rows of the grid body should be recorded on every grid refreshing. So one should do this inside of
loadComplete
orgridComplete
event handler. The functiongetColumnIndexByName
can be used to get the index of the column 'cb' with the checkboxes.
To move column inside of the table I used the following function
which can move either all columns of all rows of the table or only the rows having specific class. The row having "jqgfirstrow" class should be moved once and other rows having "jqgrow" class should be moved on every grid refreshing. So the full code from the demo will be
In the code I use some other classes and internal grid structures explained for example here. Another answer can gives additional information.