Save the sort state of a datatable

Save the sort state of a datatable

jobybaztyjobybazty Posts: 39Questions: 0Answers: 0
edited May 2012 in General
Hi,
In my application, I want to sort the table and save the state to DB, so that when I login next time I want to see table with the same order I that I sorted previously. Please help me to find a solution for this. I am using Oracle ADF ans my development environment and Oracle as my Database. I am planning to store the status to DB after sort. How can I pass the sort state to my Java class?

Replies

  • allanallan Posts: 63,397Questions: 1Answers: 10,451 Site admin
    I'd say fnStateLoad and fnStateSave are the two callbacks that you'd be interested in here. With that you can implement your own state saving method - i.e. an Ajax call to the server.

    Allan
  • jobybaztyjobybazty Posts: 39Questions: 0Answers: 0
    Hi Allan..
    thank you for the support. I am using Oracle ADF and Oracle DB. How can I get the selected value from Datatable that, which table head is clicked and in what order it is sorted. If I get this, how can I pass the value from my JQuery to my Java class?
  • allanallan Posts: 63,397Questions: 1Answers: 10,451 Site admin
    > How can I get the selected value from Datatable that, which table head is clicked and in what order it is sorted.

    Enable state saving and then use the two callbacks I mentioned before. Or you could bind a click listener to the TH elements and use fnSettings().aaSorting .

    > If I get this, how can I pass the value from my JQuery to my Java class?

    Make an Ajax call to the server which is running the Java app.

    Allan
  • jobybaztyjobybazty Posts: 39Questions: 0Answers: 0
    Hi Allan..
    Thank you very much for your valuable support. I got three values from fnSettings().aaSorting. it is
    ( 4, asc, 0 ). Forst one is the head number and the second one is the sorting order and what is the last value?
  • jobybaztyjobybazty Posts: 39Questions: 0Answers: 0
    Hi Allan...
    I am using rowGrouping to group the table rows with a condition.
    If I put the below code, the rowGrouping fails

    "fnStateSave": function (oSettings, oData) {
    alert("=== oData === "+oData);
    -- Send an Ajax request to the server with the state object
    $.ajax( {
    "url": "/state_save",
    "data": oData,
    "dataType": "json",
    "method": "POST"
    "success": function () {}
    } );
    },
  • jobybaztyjobybazty Posts: 39Questions: 0Answers: 0
    Hi Mr. Allan....
    If I get the value from DB, how can I set it back to datatable? is there any function avilabe to set it from DB to sort the state of the table ?
  • allanallan Posts: 63,397Questions: 1Answers: 10,451 Site admin
    Yes - fnSort is the one you want :-)

    Allan
  • jobybaztyjobybazty Posts: 39Questions: 0Answers: 0
    Hi Allan..
    I have a small doubt too. Is it possible to change the row values fully by drag and drop to another location in the same table?
  • allanallan Posts: 63,397Questions: 1Answers: 10,451 Site admin
    Yes - you can implement dragging just as you would with any other HTML table - but you will need to either disable DataTables' sorting, or alter your rows so when they are inserted into new locations the sorting would keep them in that place.

    Allan
  • jobybaztyjobybazty Posts: 39Questions: 0Answers: 0
    Hi Allan..

    Thank you for your support. I can save the sort order into DB and from there I set it back to datatable on page load of my application. Thank you for your support once again.

    And one more. Can you plz provide a small example for drag and drop table rows properties... it will be helpful for me in another application. Also, it it possible for saving that state too?
  • allanallan Posts: 63,397Questions: 1Answers: 10,451 Site admin
    Certainly I can provide an example of how this could be implemented. I suspect it will take about 3 hours to fully implement, so if you could pick up the 3 hour support option ( http://datatables.net/support ) I'll put the example together (although it wouldn't be Java / Oracle based!).

    Regards,
    Allan
  • jobybaztyjobybazty Posts: 39Questions: 0Answers: 0
    Hi Allan..
    Thank you for your response. Regarding the purchase of support, I have to consult with my company authorities. Once I got the reply from their end, I will contact you.
    Without disable the sorting feature, we cannt implement this? If it possible to store the order after drag and drop in to DB?

    Regards,

    Joby Joseph
  • allanallan Posts: 63,397Questions: 1Answers: 10,451 Site admin
    I don't see how drag and drop could be compatible with sorting to be honest. For example lets say you have a table with 4 rows in it and ascending aliphatic sorting applied:

    [code]
    A
    B
    C
    D
    [/code]

    If you dragged C into the top position, as soon as the table redraws (i.e. does a sort) the 'C' will end up right back where it was. If you can see a way around then, than I'm more interested to know what it is, but I don't see how the two would be compatible.

    Allan
  • jobybaztyjobybazty Posts: 39Questions: 0Answers: 0
    Yes Mr. Allan. you are correct. My question is, is it possible to implement both in the same datatable.
    Consider, one person want to sort from the table header. but another one want to arrange the table by drag and drop the table rows. That is why I asked, is it possible to apply both in the same datatabe.
  • allanallan Posts: 63,397Questions: 1Answers: 10,451 Site admin
    Yes it is possible to present both controls, but I think it would be really confusing for the end user. If they arrange a few rows and then try to sort a column, their ordering is destroyed. So yes, possible, but it would be a bit odd unless you can see a nice way of presenting it :-)

    Allan
  • jobybaztyjobybazty Posts: 39Questions: 0Answers: 0
    yes Allan. I got your point. Thankz for clarifying it. waiting for the confirmation from Manager to implement the drag and drop
  • jobybaztyjobybazty Posts: 39Questions: 0Answers: 0
    One more doubt. If i changed the order by drag nd drop, Can I save the it to DB to show the same order while login next time?
  • jobybaztyjobybazty Posts: 39Questions: 0Answers: 0
    Hi Allan...

    Saw one plugin
    http://jquery-datatables-row-reordering.googlecode.com/svn/trunk/index.html
    and I tried to implement the same in our application. I am not able to see any changes in it. I have uploaded it to debugger and the link is
    http://debug.datatables.net/oqinuf

    Can you please check is this the correct way i have impleemntd it. Now i commented out the part used for row reordering.

    You can see it there in the code as

    oTable.rowReordering(); --- as commented

    Please check it and correct me if I did anything wrong

    Regards,

    Joby Joseph
This discussion has been closed.