Order Event: how to tell if user-generated?

Order Event: how to tell if user-generated?

vangorvangor Posts: 4Questions: 0Answers: 0

Hi. The order event gets generated for multiple reasons. One of the reasons is when the user clicks on the column headers to change the sort order. Is there a way that I can tell the difference between the order event that is generated by the user changing the sort order versus the order events that are generated programmatically?

I've compared the event object generated between both cases, but I've not seen any difference. That said, the event object is quite extensive, and so I could have easily overlooked something.

Or is there a different event that I should be hooking into in order to catch when the user is changing the sort order?

Version Info: DataTables 1.10.7.

See Ya!
Van

Replies

  • allanallan Posts: 61,840Questions: 1Answers: 10,134 Site admin

    There is no way to tell if the order event comes from an end user or an API call (after all, an end user action might trigger the API call).

    What is it you want to achieve?

    Allan

  • vangorvangor Posts: 4Questions: 0Answers: 0

    Allan:

    Thanks for the quick reply!

    I want to be able to see when the user changes the sort order so that I can modify the sort order and re-apply it. Why? I need to be able to force the primary sort column to be "CustomerName", and then the column that the user selected becomes the secondary sort column.

    Initially, it appeared that order.fixed() could get the job done quite nicely. However, I also need to be able to let the user reverse the sort order of the primary column (CustomerName) by clicking on it. Unless I'm overlooking something, order.fixed() won't let me programmatically reverse the sort order of the primary column. If I'm wrong about this point, please let me know.

    I currently have the logic hooked into the order event, and it's working well for the moment. However, since the order event fires for different types of conditions, I've had to put together a "hacky" solution to ignore non-user-generated order events. For example, I have a counter that counts off the order events that occur during initialization so that the sort modification logic doesn't kick in when the page is loading. Then I've created a Boolean flag that I set when I'm programmatically resorting so that I know that the next order event was generated by my own logic, and it gets ignored. As I said, it works. However, this type of solution seems a little "brittle" so that if even a minor update occurs within the library, that logic might start malfunctioning.

    See Ya!
    Van

  • allanallan Posts: 61,840Questions: 1Answers: 10,134 Site admin

    Unless I'm overlooking something, order.fixed() won't let me programmatically reverse the sort order of the primary column. If I'm wrong about this point, please let me know.

    You aren't - the fixed order is currently, just that, fixed.

    Perhaps you could add a click event listener to the header?

    Allan

  • vangorvangor Posts: 4Questions: 0Answers: 0
    edited March 2016

    Allan:

    Do you mean assign a click event to the header? If so, I tried that, too. It's workable but also a little hacky in our architecture.

    One challenge is that the click event fires off while the order event is still running, but I can mostly work around this by calling the click logic asynchronously with Angular $timeout so that there's a good chance that the initial order event has finished processing before I apply the modified sort order and generate another order event.

    Since the simultaneous events seemed a little "brittle" as well, I opted to stick with the logic that keys off of the order event itself.

    Allan, by the way, DataTables is a fantastic library. Thanks!!!

    See Ya!
    Van

  • allanallan Posts: 61,840Questions: 1Answers: 10,134 Site admin

    Do you mean assign a click event to the header? If so, I tried that, too. It's workable but also a little hacky in our architecture.

    Yes. I think there are probably only hacky solutions to this at the moment I'm afraid. This is something I'm going to have to sit down and think about how to resolve. Possibly the original event should be passed through, although will need a few changes in the code.

    Allan, by the way, DataTables is a fantastic library. Thanks!!!

    Thank you!

    Sorry I don't have a better solution for this one at the moment!

    Allan

  • vangorvangor Posts: 4Questions: 0Answers: 0

    Allan:

    And thanks for the great support!

    See Ya!
    Van

This discussion has been closed.