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

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

RaleyRaley Posts: 7Questions: 2Answers: 0
edited September 2019 in Free community support

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

  • RaleyRaley Posts: 7Questions: 2Answers: 0
    edited September 2019

    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.

  • tangerinetangerine Posts: 3,365Questions: 39Answers: 395
  • RaleyRaley Posts: 7Questions: 2Answers: 0

    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

  • colincolin Posts: 15,238Questions: 1Answers: 2,599

    Hi @Raley ,

    The problem I believe is because you're over-writing ajax.data, not adding to it. Try this instead:

    "ajax": { "url": "./app/get_profiles.php", type: 'POST', data: function(d) { d.txt1 =  $("#rujfnhvgjcnjbcgrgdfc").text() } },
    

    Cheers,

    Colin

  • RaleyRaley Posts: 7Questions: 2Answers: 0
    edited September 2019

    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.

  • colincolin Posts: 15,238Questions: 1Answers: 2,599
    edited September 2019

    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 need serverSide enabled.

    C

  • RaleyRaley Posts: 7Questions: 2Answers: 0

    Okay, but maybe there is at least method so I can delete created rows through jquery, based on some button, or input value?

  • colincolin Posts: 15,238Questions: 1Answers: 2,599
    Answer ✓

    You can use row().remove() to remove any row, or rows().remove() to remove multiples.

This discussion has been closed.