Change "order" after Searching

Change "order" after Searching

applefanapplefan Posts: 12Questions: 2Answers: 0

Hey, does someone know how to change the "order" after searching. My Order is now like this >>"order": [[ 3, 'desc' ]],<< but I want to have it like this, when I type something in the Search Input than the "order" should change to >>"order": [[ 1, 'desc' ]],<<. How can I do this?

This question has an accepted answers - jump to answer

Answers

  • applefanapplefan Posts: 12Questions: 2Answers: 0
    edited July 2017

    Please, this one is really really needet for my Project. I want thaht the ordered column to change after search. Because when I search the first column has a bigger priority, but by start of the table, the third column is more important. Does anyone have a solution?

    Thanks

    (By the way, sorry for my bad english, im a young "developer" and not from hello world :smile: )

  • applefanapplefan Posts: 12Questions: 2Answers: 0

    Anyone please? :/

  • kthorngrenkthorngren Posts: 20,141Questions: 26Answers: 4,735

    Have you looked at order()?

    Kevin

  • applefanapplefan Posts: 12Questions: 2Answers: 0

    Yes, and I saw that I can use two render types and redraw. Like: "order( [[ 1, 'asc' ], [ 2, 'asc' ]] )". But I dont want this. The order now is on row 3. But I want, if I search, that the order changes to row 1.

    Applefan

  • kthorngrenkthorngren Posts: 20,141Questions: 26Answers: 4,735

    Not sure I understand what you are looking for. I put together this example with my understanding of what you want. Using an input box (Global Search) the example will change from column 3 desc order to column 1 asc order.

    Does that help you get started?

    Kevin

  • applefanapplefan Posts: 12Questions: 2Answers: 0

    Hey, THANK YOU SO MUCH. This is Exactly what I want. But the Problem is, it doesnt work for me :(. I use Ajax Server Side and I think it doesnt work with server-side, or? This is my Code: example . I hope you can Help me again :)

  • kthorngrenkthorngren Posts: 20,141Questions: 26Answers: 4,735
    Answer ✓

    Here is the same code using server side.
    http://live.datatables.net/qiputeri/1/edit

    If you look at the network tab and watch the requests you will see the original has this order:

    order[0][column]:2
    order[0][dir]:desc
    

    Once the search is started the request has this order:

    order[0][column]:0
    order[0][dir]:asc
    

    I tried your example but its not working. First I added the jquery and datatables CSS and JS but its still not running.

    Any draw event such as searching or ordering will cause a server side request. You may be able to use the default search input but I'm not sure what the proper selector would be. Which is why a created a new search input.

    If you still need help incorporating this functionality maybe you can use the server side base example here and build your code around it:
    https://datatables.net/manual/tech-notes/9#Server-side-processing

    Kevin

  • applefanapplefan Posts: 12Questions: 2Answers: 0

    OH MY GOD kthorngren, I LOVE YOU! Since 25 July, everyday I thinked about the Problem. And now It worked, because of you! Thank you so much!!! My Problem was, that my table Variable is just "t" and your variable was "table". I just used the Code from you and changed "table" with "t" and it worked perfectly.

    $('.dataTables_filter input').on( 'keyup click', function () {
    t.search( this.value ).order( [ 1, 'asc' ] ).draw();
    } );

    Again. Thank you so so so much <3 <3 <3

This discussion has been closed.