Selection across multiple tables

Selection across multiple tables

nick-genesisnick-genesis Posts: 5Questions: 0Answers: 0

Link to test case: http://live.datatables.net/yamoxafu/1/edit

First up, thanks Allan and co for all your work on DataTables! I've been using it for a while now and find it very useful...

I've got a situation where I have several similar (not identical, but close) datatables in different tabs on a single page. I want to enable 'os' style selection and somehow keep the selected items synchronised between the tables. i.e. any user initiated select action on any table propagates to the other tables.

See the test case of a scaled down example where I have implemented something similar to what I need, by using the the 'user-select' event, and basically re-implementing the select action. In this example though I've basically replicated the 'multi' select style, whereas I want the select style to be the 'os' style.

I've looked at using the 'select' event, which gives indexes of the new selection, except that this event is triggered whether the select is initiated by the user or the API. I need to act on the event if it's initiated by the user, but not the API, otherwise I would just create an endless loop.

Am I missing an obvious way to do this? Any ideas or suggestions?

Thanks,
Nick

Replies

  • colincolin Posts: 15,177Questions: 1Answers: 2,590

    I think this is doing what you're after - I used a combination of select and user-select to determine whether the selection was user or API generated. Could you look at that, please, and see if it helps.

    Colin

  • nick-genesisnick-genesis Posts: 5Questions: 0Answers: 0

    Thanks Colin, this is perfect....

    Much appreciated.

    Nick

  • nick-genesisnick-genesis Posts: 5Questions: 0Answers: 0

    Playing with this further, it's almost there, but not quite!
    Selection actions are propagated as you'd expect, but the deselect actions are not.

    At face value this seems like it should be as simple as using the deselect event also, but this alone isn't quite right either. This fixes the deselect problem but causes a new problem when the user does a selection that triggers both a deselect and select event. The deselect event propagates, but the select event doesn't as the user flag is now set to false...

    Any ideas?

  • colincolin Posts: 15,177Questions: 1Answers: 2,590

    Ah yep, it looks like it just needs deselect added to the same event handler - see here. Could you look at that, please, and see if it helps. If it's still not working for you, please can you give steps on how to reproduce.

    Cheers,

    Colin

  • nick-genesisnick-genesis Posts: 5Questions: 0Answers: 0

    Hi Colin,

    Thanks - this latest example causes the new problem I mentioned.

    You can see it in your example by:
    1. Select a single row in table 1. i.e Row ID 4
    - row ID 4 is selected in Table 2 as required
    2. Now select a different single row in Table 1. i.e. Row ID 5
    - row ID 4 is deselected in Table 2 as required, but row ID 5 is not selected.

    You could replicate plenty of other ways as well. Basically any user selection that causes a deselect and a select at the same time, which I think only really happens when you have an existing selection of some sort, and then click an alternate single cell (without shift or ctrl)

    I take it this compound selection action causes both the deselect and the select events to fire, and the deselect event happening first means the user variable is set to false when the select event fires.

    Appreciate your assistance!

  • colincolin Posts: 15,177Questions: 1Answers: 2,590

    Right, I think we've got it this time - it's one of those logic problems that's fun to solve :)

    The code is now checking to make sure no other operations on the other table are in action (to catch the select/deselect caused by the code), and I've added a setTimeout as I couldn't think of any other way of determining whether a select event was due to follow the deselect.

    Colin

  • nick-genesisnick-genesis Posts: 5Questions: 0Answers: 0

    Hi Colin,

    Thanks - I can't seem to break it anymore! Yep, determining whether a select event was due to follow the deselect was where I was stumped.

    Thanks again,
    Nick

Sign In or Register to comment.