Do we have a good way to store row id and column id? For jQuery, we can store data in ‘data-***’ attribute.
My scenario is this: we don’t want to expose row id which is for db internal use. And also we want to do operation on columns, for example re-order, insert and remove columns. So we also need to have unique id for columns.
Thank you very much, any help will be appreciated.
When we edit data in cell, we need to get the row id and column id to save in backend. So we need find out which the edited cell is.
When we re-order columns, we need to have a unique id which is used to talk the exactly column is, then we will also need to update backend to store column order index.
In case of these, I think the best to implement this is to have id for rows and columns. Please kindly let me know if Handsontable has such feature.
Hi @chens
To check row and col before the cell is changed you can use beforeChange callback. Here’s the example http://jsfiddle.net/handsoncode/w8en5mck/1/
It returns an array of changes[row, col, previous_value, new_value]
When it comes to moving columns there is a afterColumnMove callback that return a start and end column. Here’s a demo: http://jsfiddle.net/o9hnrqd9/ you can also use getData() to track chages or create a custom renderer to add id.
@chens: I’m not exactly sure if I understand your case correctly:
You need to store a “secret” list of ids somewhere, and use them to communicate with your database, is that correct?
If so, I think this example might help you (click the “Edit on CODEPEN” link, as the widget doesn’t display Handsontable properly for some reason): http://codepen.io/js-ziggle/pen/pypLza
It contains an object with “secret” ids with their corresponding row numbers.
I’ve made an example with the afterChange hook, but you can use it however you want - also with columns.
You need to store a “secret” list of ids somewhere, and use them to communicate with your database, is that correct?
Yes, that’s what I want. For the example you gave me, could I say that Handsontable doesn’t support to store any data in the DOM(or in option setting), right?
@chens, currently you cannot store settings like this in Handsontable’s settings. You can however put anything you’d like in DOM, as Handsontable operates on standard HTML elements.
For example, you can set attach additional data to cells using the setCellMeta method (see: http://docs.handsontable.com/Core.html#setCellMeta), and then add them to TD elements using the afterRenderer hook.