This is a migrated thread and some comments may be shown as answers.

Multi-column headers and locked columns problem, please help

1 Answer 259 Views
Grid
This is a migrated thread and some comments may be shown as answers.
fangyuan
Top achievements
Rank 1
fangyuan asked on 24 Nov 2015, 04:41 PM

I use Multi-column headers with locked columns in grid, it contains 8 columns, the 1,2,3,4th columns are top level and locked, the 5678 columns are subcolumns of the 5th column, but i find in the dataBound event, the columns.length is 8,the row's cells count isn't 8, it is just the subcolumns count, only 4, and i can't find the 1,2,3,4 column's cell in the databound event.

 

here are my code.

 

 

dataBound: function (e) {
                    var columns = e.sender.columns;
 
                    var pdColIndex = 0;
 
                    for (var j = 0; j < columns.length; j++) {
                        if (columns[j].title == 'pd') {
                            pdColIndex = j;
                        }
                    }
// columns.length is 8
 
                    var dataItems = e.sender.dataSource.view();
                    for (var j = 0; j < dataItems.length; j++) {
                        var row = e.sender.tbody.find("[data-uid='" + dataItems[j].uid + "']");
                        var pdCell = row.children().eq(pdColIndex);
 
                        // row.children().length is 4?????? can't find 1,2,3,4th column's cell.
                    }
                }

 

 

please help!

1 Answer, 1 is accepted

Sort by
0
Konstantin Dikov
Telerik team
answered on 25 Nov 2015, 02:26 PM
Hello,

When there are frozen columns, the Grid will render two different TABLE elements for the left and the right part, which will result in two separate TR elements corresponding for each item. When you try to get reference to a particular TD element, based on the column index, you need to find both of the TR elements and make your logic to take into account the structure of the grid. 

An easy approach for your scenario is to find all TD elements that from both of the TR elements and use the index there:
for (var j = 0; j < dataItems.length; j++) {
    var rowCells = e.sender.element.find("[data-uid='" + dataItems[j].uid + "'] td");
    console.log(rowCells.eq(pdColIndex).html());
}

Hope this helps.


Regards,
Konstantin Dikov
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
Tags
Grid
Asked by
fangyuan
Top achievements
Rank 1
Answers by
Konstantin Dikov
Telerik team
Share this question
or