why don't jquery datatable get filled with newly updated data after searching?
why don't jquery datatable get filled with newly updated data after searching?
Hunayn
Posts: 7Questions: 2Answers: 0
Link to the original question:
This question has accepted answers - jump to:
This discussion has been closed.
Answers
What is in the JSON response from the server for your search?
Kevin
{"draw":1,"recordsTotal":10,"recordsFiltered":25,"data":[["Hunain","123"],["Hunain","123"],["ravaid"
,"123"],["Waleed","123"],["Jim Carrey","123"],["da","asd"],["hunain","321"],["sd","asd"],["bekhudi","123"
],["hk","asd"]]}
@kevin
{"draw":1,"recordsTotal":10,"recordsFiltered":25,"data":[["Hunain","123"],["Hunain","123"],["ravaid"
,"123"],["Waleed","123"],["Jim Carrey","123"],["da","asd"],["hunain","321"],["sd","asd"],["bekhudi","123"
],["hk","asd"]]}
This is in the JSON:
recordsTotal
should be the total in the DB not what was returned. This doc describes the parameters returned from the server.I'm not sure if it will cause problems to report more
recordsFiltered
thanrecordsTotal
. Maybe you can provide a debug report after the initial table load and one after performing the search. Or if you can provide a link to the page with the problem someone will take a look.Kevin
I'm not sure that's what you want, looking at the docs:
https://datatables.net/reference/option/retrieve.
@kthorngren
thanks for the reply pal but that didn't work.
I am posting a Request and response after initial table load and after performing a search
After initial load:
Request:
_
1503560388132
columns[0][data]
0
columns[0][name]
columns[0][orderable]
true
columns[0][search][regex]
false
columns[0][search][value]
columns[0][searchable]
true
columns[1][data]
1
columns[1][name]
columns[1][orderable]
true
columns[1][search][regex]
false
columns[1][search][value]
columns[1][searchable]
true
draw
2
length
10
order[0][column]
0
order[0][dir]
asc
search[regex]
false
search[value]
2
start
0
Response:
{"draw":1,"recordsTotal":4,"recordsFiltered":25,"data":[["Hunain","123"],["hk","asd"],["daenerys Targaryen"
,"123"],["",""]]}
After performing a search:
Request:
_
1503560409319
columns[0][data]
0
columns[0][name]
columns[0][orderable]
true
columns[0][search][regex]
false
columns[0][search][value]
columns[0][searchable]
true
columns[1][data]
1
columns[1][name]
columns[1][orderable]
true
columns[1][search][regex]
false
columns[1][search][value]
columns[1][searchable]
true
draw
2
length
10
order[0][column]
0
order[0][dir]
asc
search[regex]
false
search[value]
w
start
0
Response:
{"draw":1,"recordsTotal":1,"recordsFiltered":25,"data":[["Waleed","123"]]}
@tangerine that didn't work man, thanks btw
It's done. Thanks for the help guys.
The reason was that draw parameter being sent and received was not same because I took draw static in the server code so mismatched. I returned the same draw parameter as it was sent.
but
That's the problem. From the documentation:
Allan
p.s. If you only have 25 records in the table, don't use server-side processing. You should only consider server-side processing when you had thousands of rows, since otherwise you are just introducing latency into your application. Even then, I would typically only recommend it when you are working with tens of thousands of rows.
Allan