Events broken after sorting/manipulating rows

Hi. :slight_smile:

Finding out what the user clicked by listening for selection, e.g.

myGrid.attachEvent("onRowSelect", callback);

does not work properly for added rows or sorted rows.

How can I re-initialize the event properly to update row content returned to the callback?

I tried to detachEvent and attachEvent after a change like this, but detachEvent doesn’t seem to do anything.

Unfortunately the issue cannot be reproduced locally.
If issue still occurs for you - please, provide with any kind of sample of your code or a complete demo, where the issue can be reproduced locally.

Sample code to attach to grid. Here’s a step by step.

  1. Have a grid with some content prior to attaching onRowSelect.

  2. Attach onRowSelect.

[code]myGrid.attachEvent(“onRowSelect”, function(id, ind) {

// Log first cell of clicked row
var cell = gridCats.cellByIndex(id, 0);
var value = cell.getValue();
console.log('Value: ' + value);

// Add new row
var id = new Date().getTime();
myGrid.addRow(id,['Blah blah', null]);

});[/code]

  1. Run the app

3a) Click on a row, and the value of the first cell will be logged. A new row will be added.

3b) Click on the new row, and you get an error:
Uncaught TypeError: Cannot read property ‘0’ of undefined dhtmlx.js:855

3c) Click on an old row (e.g. 1st) again and you will see a value.
3d) Sort the rows by clicking the column headers.
3e) Click the row at the same position (e.g. 1st) you will get the value that it had BEFORE it was sorted.

-edit- gridCats should be myGrid.

I cannot edit my post. But I copy-pasted that line from my code, forgot to change it. :stuck_out_tongue:

Unfortunately the issue still cannot be reproduced locally.
Your code works well for us. If the issue still occurs for you - please, provide with a complete demo, where it can be reproduced.
Here you can find a tutorial about creating a complete demo:
docs.dhtmlx.com/doku.php?id=othe … leted_demo

Did you even try? Some of the bugs you say aren’t reproducible are pretty obvious.

Maybe the policy is to not check it out unless someone makes a testcase. That’s fine, but just say so. :sunglasses:

Here I made one with love. (see attachment)

Firefox 24:

Chromium (Chrome) 29:

Opera 12.16

Case 1: Just do what the testcase sais (click first row, then click new row)

Case 2: Add dhxGrid.setColSorting("str"); , sort the rows so they are the other way around and click. The name is returned from before sorting.
grid_event_not_updating.zip (614 KB)

In your provided demo:
var cell = dhxGrid.cellByIndex(id-1, 0);

while:
var id = new Date().getTime();
dhxGrid.addRow(id,[‘NOW CLICK ME!!!1’, null]);

“new date - 1” won’t be the index of the row.

Please, try to get the cell object using the row id:
dhxGrid.cells(id,ind)
or by the index:
dhxGrid.cellByIndex(mygrid.getRowIndex(id), 0);

Yes that works! I was using the callback vars wrong. It just appeared to work because the default row IDs are almost similar to default index. Your solution was very simple.

var cell = dhxGrid.cellByIndex(id-1, 0); // Bad
var cell = dhxGrid.cells(id,0); // Good

Thank you!