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

$(cell).index() INTERMITTENTLY returns incorrect column index

0 Answers 136 Views
Window
This is a migrated thread and some comments may be shown as answers.
Tim R
Top achievements
Rank 1
Tim R asked on 13 Mar 2013, 08:23 PM
EDIT: This was happening because the cell sometimes contained a DIV, and the DIV, not the TD, was the event target, which messed up the code that gets the cell-index.  
  
IIt may be my error, or it could be a problem with the grid or jQuery.  My code is shown below.  I'm clicking on the same column, choosing a different row at random, and every so often, the wrong column-index is returned. I cannot figure out why it works most of the time, but not always.  I'm clicking on a column whose index is 7. Sometimes zero is returned.

function addCellClickEventListener() {
    var grid = $('#grid').data('kendoGrid');
    $(grid.tbody).on('click', "> tr:not(.k-grouping-row, .k-detail-row, .k-group-footer) ", function (e) {
        popup(e);
    }); 
}
 
 
function popup(e) {    
    var cell = e.target;
    var ix = $(cell).index(); 
    assert((ix != 0), "index must be greater than zero"); 
}
 
 
function assert(val, msg) {
    if (!val) {
        alert(msg);
        return false;
    }
    return true;
}

No answers yet. Maybe you can help?

Tags
Window
Asked by
Tim R
Top achievements
Rank 1
Share this question
or