Dhtmlx grid header , Attched header row index

we have editable header & attached header in the grid.
      our application required to save header and attached
  header text/data of respective cell,We are getting column index but not row index.
How to get row index of header & attached header?
   

The header is not included in grid data model, it is separate instance and grid doesn’t provide API to access it, but if necessary you can access header content by next code

    var hdrCell=grid.hdr.rows[hdrRowIndex].cells[cellIndex]
    alert(hdrCell.innerHTML);

hdrRowIndex - 1-based index of headers row. Top header row has hdrRowIndex==1

This is a very old post, so it is likely the approach to reading grid header content has changed. At least I hope so, since the approach documented here does not work.

I have a grid with a single header row. After the grid is loaded I sometimes add 2 additional header rows using attachHeader method. When I use the approach noted in the post, the “hdr” object has only two rows - those associated with the original grid construction: a TH row and then the row with my grid column headings.

Bottom line, then: Is there a clever way I can access the content of the “attached” headers?

You can access content of attached header with getColumnLabel() or with getFilterElement(index). What exactly do you want to find in grid header?

Your question is a reasonable one…

I’ve got my own data filter interface initiated by a toolbar button, that accepts complex data searches such as A or B and (c or D) and “Quoted String”. And appropriate set of WHERE clause content is automatically generated so that specified table columns are examined for the searched-for strings, and their related boolean operators. Naturally the generated syntax can be both complex and lengthy, and somewhat geometrically lengthened by the number of fields to be examined. Add to this that CONVERT(xxx, CHAR) must be used since some of the fields to be examined may be integer or decimal fields. The WHERE clause syntax is automatically integrated with whatever otherwise-applicable WHERE clause content is present, and the resultant query passed to MySQL. Then, as part of the AJAX program that returns the DHTMLX grid XML, where there were data matches, the grid cell has content selectively highlighted. For example, if I was searching for “lg” a cell containing OLga would be defined to be OLga. This is a very simple example, of course.

In addition, if such a search is active, one ought to provide a user-friendly display that shows what the current active filter is. So I attach a header beneath the column headings (spanning all headings) that includes an “English” version of the requested query. Here’s a sample:


Having such an explanatory header has the added benefit of being included in the generated PDF if the Grid2PDF feature is used (as is the case as well in this example).

The reason for asking how to get header content is as follows. Since the generated SQL code can be lengthy, I added a debug option that implanted the generated SQL in a second attached header. I thought to add a “copy SQL” link at the end of this code so that I could, if I wanted to copy the code, click the link and have the code moved to the clipboard.

A long answer to your question…

Finally, to illustrate the “data filter” interface itself, see the attached screenshot.


To access column header label you can use:

  1. If header cell is quite straightforward and doesn’t contain complex html, you can use getColumnLabel() method:
    var colLabel=mygrid.getColumnLabel(column_index,row_index);
    where column_index - zero-base column index
    row_index - zero base header row index (in your case it is 1)
    This method will return innerText of “td” element in header.

  2. You can access to the header cell directly from DOM with following code:

var td=mygrid.hdr.rows[row_index].cells[cell_index]

In such case row_index is 1-base. In your case it is 2.