How to tell if a column is being sorted?

How to tell if a column is being sorted?

CGRemakesCGRemakes Posts: 32Questions: 1Answers: 0
edited November 2012 in General
I'm using a combination of server-side processing and jeditable. I'd like to make it so it only gets the ajax data after an edit if the column they are editing is being sorted. My thinking is there is no reason for the extra load (and losing the user's place on the scroll as a result) unless the change will ultimately affect the sorting. How would I go about doing this? Let me know if this doesn't make sense, or if there's a better way to go about doing this.

EDIT: I think I found what I'm after here: http://datatables.net/forums/discussion/11390/how-to-get-values-of-the-current-sort-column-index-and-direction-from-aodata/p1

Replies

  • CGRemakesCGRemakes Posts: 32Questions: 1Answers: 0
    edited November 2012
    Well, I did get it to work as I thought I wanted, but I'm not sure it's really what I want. My issue is that there are sometimes several rows that need to be edited. After each edit, a reload of the ajax would be helpful since the sort order may change as a result of the edit, or, because of filters the user has in place, the row may no longer even appear after the change. However, after the reload, it starts back over with row #1. If there are several changes they need to make, and the records are several thousand rows in, it's an awful lot of extra work to scroll after every single edit. Another option I suppose I have is after the reload, I could use scroller and just have it scroll automatically back to the row # I was editing. Is this the only solution?
  • allanallan Posts: 63,523Questions: 1Answers: 10,473 Site admin
    A standing redraw is a bit of a weak point in DataTables at the moment I'm afraid, particularly when scrolling is enabled. The best that can be done at the moment is to save the scroll position before you update the table and then restore it after the table has redrawn - messy I know, but this is certainly something that I plan to look at and improve for v1.10.

    Sorry I don't have a better answer at the moment.

    Allan
  • CGRemakesCGRemakes Posts: 32Questions: 1Answers: 0
    edited November 2012
    That's kinda what I figured. It's probably an acceptable workaround until something else comes along. Thank you for the reply and the service you provide.
  • CGRemakesCGRemakes Posts: 32Questions: 1Answers: 0
    Hmm.... trying to get the fnscrolltorow function to work. I save the row # that's being edited as a global var row_edi_num, then as the last step of the fndrawcallback function, I run the following command:

    [code]

    if(row_ed_num != '0')
    {
    oTable.fnSettings().oScroller.fnScrollToRow(row_ed_num);
    row_ed_num = '0';
    }
    [/code]

    I alert the row_ed_num value inside the condition, and it does display the proper row #. However, it sits there for a few seconds, then displays the results from row 1 again, regardless of the value of row_ed_num. Is there something that fires after fndrawcallback function where I need to put that?
This discussion has been closed.