0

I was wondering if there was a way to retrieve the rowspan and columnspan attribute value of a cell in jqGrid? My intent is to get the currentrowspan and columnspan attribute value and increase it by one if needed based on the previous row's cell value.

I have looked through all the documentation but it doesn't look like there is a way to getthe attribute values like rowspan and columnspan of a cell.

Thank you

user3605100
  • 33
  • 2
  • 8

1 Answers1

0

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.

Community
  • 1
  • 1
Oleg
  • 220,925
  • 34
  • 403
  • 798
  • My idea is to merge cells if the values are same amongst subsequent rows. So in the column Model cellAttr function I am thinking I would get the cell Value and compare it with the previous row. If the previous row and current are same then I would set the rowSpan to be 2 for the previous row and for current row set it as display:none. – user3605100 Jul 26 '15 at 21:39