Redraw table is showing different number of rows each time

Redraw table is showing different number of rows each time

sec12tst8r84sec12tst8r84 Posts: 4Questions: 1Answers: 0

Thank you for making such a great product. I'm trying to reload a server side table after data has been changed on the server. I've tried the draw() as well as DataTable().ajax.reload(); The weird thing is, I have two functions that utilizes reload. Edit_row (Update button) works after click on it twice whereas Setup (Setup button) does not.

When I click the Setup button, different number of rows is returned each time. All columns are NULL. There shouldn't be any filtering but here is what is returned after several instances of clicking Setup:
No matching records found / Showing 1 to 0 of 3 entries (filtered from 4 total entries)
Showing 1 to 20 of 27 entries (filtered from 28 total entries)
Showing 1 to 22 of 29 entries

It should be showing 1-29 of 29 entries.

You can see my page here: http://ginkgo.duckdns.org:8888/514Creek/514Creek.php . The Setup button is at the top and the Update button is to the right of the Sales Date. The Setup button is not working but the Update button is kind of working. The initial load works fine. If I click on Setup, it goes wonky. If I then click on Update, some but not all of the data is shown. If I click on Update again, then all the data is shown.

I've uploaded my files but here is the relevant piece of code (I've deleted the irrelevant parts to make it shorter):

Thank you very much for your help!
Sharlene


$(document).ready( function () { var list =[6,3,8,3,10,5,0.5,'2000-01-01']; var table = $('#trans').DataTable({ dom: 'Brtip', buttons: [ ], processing: true, paging: false, scrollX: true, scrollY: 500, scrollCollapse: true, ordering: false, columnDefs:[ ], fixedColumns: true, fixedColumns:{leftColumns: 1}, serverSide: true, ajax: { url: "../server_side/server_processing.php", type: "POST", data: { //list: list, prop: '514Creek' } }, createdRow: function ( row, data, index ) { } }); }); function edit_row(){ var list =[6,3,8,3,10,5,0.5,200000,'2000-01-01']; list[0] = document.getElementById("t_app").value; list[1] = document.getElementById("t_exp").value; list[2] = document.getElementById("t_vac").value; list[3] = document.getElementById("t_rent").value; list[4] = document.getElementById("t_tax").value; list[5] = document.getElementById("t_salesdate").value; list[6] = document.getElementById("t_lc").value; list[7] = document.getElementById("t_mgmt").value; $.ajax({ type:'post', url:'future.php', data:{ edit_row:'edit_row', list:list }, success:function(response) { if(response=="success") { document.write("success"); } } }); $('#trans').DataTable().ajax.reload(); } function createdata(){ $.ajax({ type:'post', url:'../createdata.php', data:{ function2call: 'setup', prop:'514Creek' }, success:function(response) { if(response=="success") { document.write("success"); } } }); $('#trans').DataTable().ajax.reload(); }

Answers

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

    Not sure what your server scripts are doing but or why the data is null sometimes. I'm not able to download the attached PHP scripts.

    I'm wondering if you really need server side processing enabled. How many records do you expect in production?

    You have paging: false, which defeats the purpose of server side processing and retrieves all the records.

    Your draw parameter in the response is always0`. It should match the draw counter number that is in the request. Here is the documentation:
    https://datatables.net/manual/server-side#Returned-data

    Not that this will fix data issues but does the table work if you remove serverSide: true,?

    Kevin

  • sec12tst8r84sec12tst8r84 Posts: 4Questions: 1Answers: 0

    Hi Kevin, thank you for responding to my question.

    I had server side on because I thought since the data is pulling from a mysql table, that's a server. I guess I misunderstood.

    The number of records shown currently is the number of records there will be in production.

    I tried removing serverside: true, adding draw: 1, adding both draw: 1 and serverside: true.

    I can email you the files if you'd like to take a look.

    Thank you,
    Sharlene

  • sec12tst8r84sec12tst8r84 Posts: 4Questions: 1Answers: 0

    Not sure what I did but it's working now. If I ever figure out what went wrong, I will update this post.

    Sharlene

This discussion has been closed.