adding newNode as a parameter to deselect row

adding newNode as a parameter to deselect row

dan@19ideas.comdan@19ideas.com Posts: 56Questions: 13Answers: 1

I've came across this crossroad at least 3 times in my project. There is a time when I want to know if a user deselected a row because it was intentionally deselected, or if a row was deselected because another row was selected. The problem occurs because I have operations happening on a deselect event that I don't want to occur if the user was switching to another record, meaning that the select/deselect events trigger when other rows are being selected.

So I'm thinking it would probably be better if we can add a "nextSelection" or "newNode" parameter in the deselect method, and check the contents of the new node, or we could just send a boolean checking the the existence of "isNewNodeSelected". On my end, I have to do a sequence order to make sure it captures newly selected data, before entering the deselect event trigger, and then store the values and compare that way. But it's become very tedious to set up.

Replies

  • colincolin Posts: 15,240Questions: 1Answers: 2,599

    Hi @dan@19ideas.com ,

    No, you can't really tell as this example shows. Selecting another cell causes a deselect in the same way. You maybe able to try standard jQuery events, as in this example, as this just deals with the click.

    Not much use, but hope that helps,

    Cheers,

    Colin

  • dan@19ideas.comdan@19ideas.com Posts: 56Questions: 13Answers: 1

    Well the click event to me is the same way as using the select event. If I used a click event, i'd just move all my code from the select method to the click method, not anything I'm already doing in the deselect method.

    On deselect for example, I had to hide certain elements from showing. But when I switch to another record, it hides, then shows, and does other methods. There's no way of telling in the deselect method what is actually happening.

    I'm not sure how to do that using jquery click event since the click event doesn't give me any information about deselecting an item.

  • dan@19ideas.comdan@19ideas.com Posts: 56Questions: 13Answers: 1

    This can be a bit cumbersome if you load an ajax request on each event, where if you have a select, you send data via ajax to update that values, and when you deselect, you send an ajax to remove the values.

    If you switch to another record, you're essentially executing two ajax calls, the deselect, then the select.

    If a new parameter was added to the deselect event, all you'd have to do is check for the validity that something else was selected, and ignore certain parts of the code.

    Again, I tried looking for jquery events, and other solutions in figuring this out, the only way I'm doing this, is saving the value of the previous record somewhere else and doing a comparison check with a newly selected record, then doing a check to see if the deselected record and selected record are the same, and make sure that when I do these comparisons to continuously update the previous record state. All of this work on my part would be replaced with the new parameter added to the deselect functionality.

  • dan@19ideas.comdan@19ideas.com Posts: 56Questions: 13Answers: 1

    actually.. I would also accept changing the ordering of when the events are fired.. if the select event was triggered before the deselect event, then I could just set a flag telling the deselect that a new record was selected. That would work just as well.

  • allanallan Posts: 63,572Questions: 1Answers: 10,482 Site admin

    user-select is the one you want here. That will trigger when the user selects a new row and you can use a flag to know in the deselect should trigger its Ajax call or not.

    Here is an example: http://live.datatables.net/letorula/1/edit .

    Regarding the order - the current order of deselect and then select is correct and won't change. It is that way around to allow for limiting of row selection (e.g. to a single row).

    Allan

  • dan@19ideas.comdan@19ideas.com Posts: 56Questions: 13Answers: 1
    edited July 2018

    Side-note, forget what I mentioned about the ordering.. it doesn't matter.. if I deselect regardless and I never chose another record, there would be no ajax (even though there should be.. to wipe the data on the server).

    I'll try the user-select event.. I just noticed what you mean in your example.

  • dan@19ideas.comdan@19ideas.com Posts: 56Questions: 13Answers: 1

    Hi Allen,

    Yeh it doesn't work. In your example, I don't see how I can reach the "row deselected" code. It seems user-selected event gets triggered all the time, no matter what record I'm selected/deselecting.

    Also, if the user-event has information about the next node its trying to access, I'd like to know how to get it, so I know if it's null or not.

  • allanallan Posts: 63,572Questions: 1Answers: 10,482 Site admin

    I'm with you now, a little modification of the logic should do it: http://live.datatables.net/qezepito/1/edit .

    Allan

  • dan@19ideas.comdan@19ideas.com Posts: 56Questions: 13Answers: 1

    Wow, exactly what I needed. Yesterday I merged my deselect ajax with my select ajax, so the server side accepts the different value coming in, and I used your code as a basis to put all the logic in user-select, and it worked! This also reduced my code in the 3 places I mentioned earlier, and I see a lot less network overhead now.

This discussion has been closed.