Sorting and filterting doesn't work when sending POST data through AJAX
Sorting and filterting doesn't work when sending POST data through AJAX

Hi, I wasn't able to find any solution on your site, or maybe I'm just a terrible seeker, anyway, Im' trying here.
So, I wanted to customize my datatables, so I can show a hidden (by status value in mysql) records only to admins. I decided that the best solution will be to create a simple, hidden form only for admins, and then set some hidden input, pass it through AJAX with my datatable, and then read it in my server-side script, modifying my query depending on if that value was passed.
Here's my code for the hidden input:
<form method = 'POST'>
<input type = 'hidden' name = 'rujfnhvgjcnjbcgrgdfc' id = 'rujfnhvgjcnjbcgrgdfc'/>
</form>
Server-side script (changed lines):
if(isset($_POST['txt1'])){
echo json_encode(
SSP::simple( $_GET, $sql_details, $table, $primaryKey, $columns )
);
}else{
$whereAll = "profile_status = 1";
echo json_encode(
SSP::complex($_GET, $sql_details, $table, $primaryKey, $columns, $whereResult = null, $whereAll)
);
}
And my "AJAX" parameter when creating my datatable:
"ajax": {
"url": "./app/get_profiles.php",
type: 'POST',
data: {
txt1: $("#rujfnhvgjcnjbcgrgdfc").text()
}
},
Can you help me out? Or maybe you guys have better solution to show hidden (mysql value) records only to admins?
This question has an accepted answers - jump to answer
Answers
Actually, I don't even have to send anything. If I'd do just something like this:
"type": "POST",
Search option and column sorting doesnt work. I tried so many ways and I'm stuck with it.
Please provide a test case where we can see your code working.
https://datatables.net/forums/discussion/12899/post-test-cases-when-asking-for-help-please-read#latest
Here is a link (just a test host)
https://7sd8dfyhfdb.xaa.pl/xvj7hfvuncfubf/index.php?page=profiles
Account credentials:
Login: admin
Password: asdasdas
As you would see, sorting and filtering does not work if I just add
"type": "POST",
to my ajax request (no matter if I pass any data)
Sorry for my late response and lack of test case
Hi @Raley ,
The problem I believe is because you're over-writing
ajax.data
, not adding to it. Try this instead:Cheers,
Colin
Hi @colin ,
Thank you for your response, unfortunately, it does not fix my problem. I tried your way, but nothing has changed. I'm able to read txt1 in my server side script (I was all the time), but as I mentioned before, sorting and filtering are still not working.
Ah, sorry, I missed that bit. That's because you've enabled
serverSide
- that expects the server to do the ordering and filtering and only return back the relevant records. If your table is small, you won't needserverSide
enabled.C
Okay, but maybe there is at least method so I can delete created rows through jquery, based on some button, or input value?
You can use
row().remove()
to remove any row, orrows().remove()
to remove multiples.