How to make search with Ajax instead of default filtering data

How to make search with Ajax instead of default filtering data

inajafinajaf Posts: 13Questions: 8Answers: 0

Guys how to make a search with Ajax with child rows datatables
For example data tables https://jq22.com/demo/DataTables-141023114035/examples/api/row_details.html

I am trying this example: https://datatables.net/examples/server_side/simple.html

It's not worked for my script https://jsfiddle.net/inajaf/g8zuL705

Answers

  • kthorngrenkthorngren Posts: 15,720Questions: 25Answers: 3,724
    edited December 2021

    You are trying to use an ajax request in columns.render. This is not recommended as the ajax request will be sent for each row. It looks like you have defined the ajax request in 4 columns so it will actually send a request 4 times for each row.

    The request looks to be the same each time, i, the url doesn't change and you are sending any data via the data object. A simple option wold be to use the ajax request once before initializing Datatables and set a global variable that can be used in the columns.render functions.

    Kevin

  • inajafinajaf Posts: 13Questions: 8Answers: 0

    Hi @kthorngren , Thank you for mentioning about 4 requests, unfortunately, I tried to call ajax data before datatables initialization, but can't it used inside Datatables, the data not showing

  • colincolin Posts: 14,158Questions: 1Answers: 2,399

    Can you update your test case, please, to demonstrate that. It would help us to understand the problem if we can see what you're doing,

    Colin

Sign In or Register to comment.