One should be very carefully if one changes rowspan
and colspan
attributes of jqGrid to hold the look of the grid correct. One have to change the values not only one cell, but multiple cells to to hold the look of the grid correct. The answer provides an example of usage rowspan
and another one the usage of colspan
.
If possible you should follow the referenced examples and set rowspan
and colspan
attributes during creating the grid instead of changing the attributes late. The reason of that is the performance. If you change one element on HTML page then the position and some other attributes of many other elements on the page can be changed, so the web browser need to do reflow to verify whether the changes are required. It takes time. The more elements you have on the page the more expensive is changing of one element. Because of the reason jqGrid try to create the grid with all elements and attributes as one operation (see gridview:true option). It can dramatically improve the performance of the page in case of working with large grids.
In any way I can ask you how to get the cell and change it's attributes. Probably you know that jQuery will be used mostly as wrapper object of DOM elements, which is the standard interface to represent or change elements of the HTML page. It's important to understand, that jQuery uses typically only one common Element interface which is inherited by all HTML elements. On the other side there are many other helpful interfaces which can be used to access to HTML page. jqGrid are based on HTML <table>
element which supports many other helpful properties (see here for example). So if you created jqGrid from <table id="grid"></table>
for example, then $("#grid")
represent jQuery wrapper to the grid. To access to the rows of the grid one can use rows
collection and to access to the cells of the row one can use cells collection of the row. Thus one can use $("#grid")[0].rows[iRow].cells[iCol]
to access to the cell of the row:
var gridDom = $("#grid")[0];
// the iRow row (1-based) and iCol
var oldRowSpan = $(gridDom.rows[iRow].cells[iCol]).attr("rowspan");
By usage jQuery.attr
one can get or set any attribute of the cell (rowspan
and colspan
attributes for example). The only thing which one should take in consideration: one should don't change the first non-visible row of the grid $("#grid")[0].rows[0]
. The row have class jqgfirstrow
. The row has the index 0. Other standard rows of jqGrid have class jqgrow
and have the index starting with 1.