How to remove a deselected row's equivalent from a second table: store index of row on select?

How to remove a deselected row's equivalent from a second table: store index of row on select?

Bob RodesBob Rodes Posts: 17Questions: 1Answers: 0
edited July 2016 in DataTables 1.10

I'm working with someone on this. Here is a link to a live table with the problem set up. It's easy enough to add the selected row in table A to table B, but what we'd like to do is remove said row in table B when deselecting it in table A. I've tried a number of ways (applying variations of the examples for the deselect event) to store the row index of selected row in table A to table B when adding it, but I haven't found a solution and the code gets messy fast.

What's the best way to accomplish this? Do we need to add an ID row to the actual data, and find it that way (I'd rather not)? I've tried using the jQuery data() method to attach the index to the row in the select handler, which would be ok. But do I need to do that? I have the feeling there's something simpler that would be good to know.

Replies

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin

    You need some way to tie the original row to the cloned row in the child table. That is probably going to involve using an id, or otherwise unique data (for example the name if you know what will be unique in your data set).

    You possibly could use the original data array for the row (which is what row().data() returns), but I think that could be potentially quite fragile, particularly assuming you want to do something with the second table rather than just displaying the data.

    The approach I would take is to use a column with unique data in it and then find that from the delselected row's information and remove it.

    Allan

  • Bob RodesBob Rodes Posts: 17Questions: 1Answers: 0

    Thanks Allan. That's what I was thinking too, but I wanted to see if there might be something more direct that I didn't know about.

This discussion has been closed.