PDA

View Full Version : Adding a "delete" link in each row of a grid



cwells
21 Dec 2006, 1:19 PM
I've got the basic EditableGrid working in my application (AJAX populated from server), but my question is this: how can I add a column (probably with a little "X" icon in it) to each row that would allow me to delete that particular row? I know RemoveRow() is used to delete a row, but I'm stuck on how to properly add the column and tie an event to it. An example would be appreciated.

Regards
Cliff

tryanDLS
21 Dec 2006, 1:41 PM
I think there's a thread on this, but basically, you could
a)add a dummy column to the cm and dm.
b)add a dm preproccessor to init that value for each row as the data is loaded (e.g. to blank)
c)add renderer for that column in your cm to return an HTML string that will get put into the cell for each row.
d)add an function to handle the grid's cellclick event to do something with the row.

Another way would be to make the cell a checkbox to indicated deleted. Then process all the flagged rows on something like save button. This way you don't have to try and get an image or link to render in the cell, you could just use CheckBox cell editor.

cwells
21 Dec 2006, 3:15 PM
I think there's a thread on this, but basically, you could
a)add a dummy column to the cm and dm.
b)add a dm preproccessor to init that value for each row as the data is loaded (e.g. to blank)
c)add renderer for that column in your cm to return an HTML string that will get put into the cell for each row.
d)add an function to handle the grid's cellclick event to do something with the row.


It took me a little bit to put together, but it works =) Thanks! I had everything up to part d).
The key was not trying to hook an event handler to each "delete" cell but rather to simply get the cellclick event for the entire grid and check if the click happened within one of my "delete" cells and if so, grab the rowIndex from that event.

Anyway, you put me on the right track with the cellclick event, thanks.