Implementing client-side date filtering with 'serverSide:true' setting

Implementing client-side date filtering with 'serverSide:true' setting

muallimimmuallimim Posts: 4Questions: 2Answers: 0

I am using it as "serverSide:true."

The server-side code is not suitable for filtering between two dates. Therefore, I wrote a function for filtering using the "minDate" and "maxDate" components that I placed within the table. It works correctly when "serverSide:false." However, when "serverSide:true," it tries to send data to the server when entering date information, causing issues.

Normally, it should remain as "serverSide:true." However, it should only perform "client-side" processing for date filtering.

Answers

  • kthorngrenkthorngren Posts: 21,443Questions: 26Answers: 4,974

    When using server side processing (serverSide: true) none of the client side capabilities, ie filtering, of Datatables is supported. If it did work the date range filter would only apply to the rows displayed on the page as they are the only rows at the client.

    To support the date range search the server script will need updated to filter the search results including the date range. You can use the ajax.data option as a function to send the "minDate" and "maxDate" values as extra parameters. See this example. The server script will need to parse those values from the Ajax request to use as part of the data query.

    Kevin

  • muallimimmuallimim Posts: 4Questions: 2Answers: 0

    But I don't have the right to modify the code on the server side, and I want to solve the filtering between two dates on the client side.

  • kthorngrenkthorngren Posts: 21,443Questions: 26Answers: 4,974

    The Datatables search functionality doesn't support any client side filtering options if server side processing is enabled.

    The only thing I can think of is to do something that Datatables doesn't support which is hiding the rows using Javascript or jQuery. This will only affect the rows being displayed on the page as they are the only rows at the client. The problem is each time Datatables redraws (paging, searching or sorting) the table these hidden rows will be shown as Datatables doesn't know about them. You could use the draw event to check if there is a data range specified an if so hide the rows that are out of the range.

    Doing this will filter the rows client side. But you will likely end up with a table that displays a different number of rows each time it is drawn. For example Datatables displays 10 rows by default and the date range filter might hide 4 rows so only 6 are displayed. Going to the next page might filter 1 row so 9 are displayed.

    Again this is not a Datatables supported solution.

    Kevin

Sign In or Register to comment.