How server side processing with DataTable works?

How server side processing with DataTable works?

aylinaaylina Posts: 2Questions: 1Answers: 0

Debugger code (debug.datatables.net):
http://live.datatables.net/nirosoko/3/edit
Description of problem:
I'm pretty new to nodejs and expressjs. I am trying to use datatables with serverside processing. I have a large number of records and I only pull 10 records from the database and display them on the screen. With the pagination method, when I go to a forward page, I pull and show the other 10 records. But I am not sure how to use the search area. While these are ready in client side processing, we need to add queries ourselves in server side processing. But the data I show on the screen comes from more than one table. I'm not sure how the searching area should work, whether this is how server side processing should work, if I'm doing the right thing. I will be grateful if you could help me.

I want the search area to work only when enter is pressed. But when I type something in the search section and press enter, first /search and then /getAllDevice part is called and the page is not refreshed. How can I prevent this?

Answers

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin

    When you are using server-side processing with DataTables, the filtering must be done at the server-side. DataTables submits a search object which contains information about the current search which you need to use. The parameters are documented here.

    If you didn't want to write your own server-side processing script, you could consider using our NodeJS libraries.

    Allan

  • aylinaaylina Posts: 2Questions: 1Answers: 0

    Hi Allan, thank you for your interest. Did you see my example? I'm not sure I did correct implementation. I have a problem like this:
    When I type something in the search section and press enter, first /search and then /getAllDevice part is called and the page is not refreshed. When I switch between pages, I want /getAllDevice part to work, and when I search, I want /search part to work. How can I achieve this?

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin

    Just to confirm my understanding - you want to change the request URL based on if there is a search string or not?

    If so, you would need to use ajax as a function and have an if statement inside it which checks if there is a search term or not.

    Also

    "draw": 1,

    is wrong in your code. From the manual:

    The draw counter that this object is a response to - from the draw parameter sent as part of the data request. Note that it is strongly recommended for security reasons that you cast this parameter to an integer, rather than simply echoing back to the client what it sent in the draw parameter, in order to prevent Cross Site Scripting (XSS) attacks.

    Allan

Sign In or Register to comment.