How do I rebuild the datatable with new columns with server side processing

How do I rebuild the datatable with new columns with server side processing

TroyCroweTroyCrowe Posts: 8Questions: 1Answers: 0

I have server side processing working on all tables where the columns are static. I have a need for the table to be different based on the selected client. I am able to load an empty table with one column that shows the standard data of no records. However, when I user jquery to recreate the table structure after calling the datatable destroy method the path which worked to build the table initially provides me a 404 error. The path is correct, as I said it is the same path used to build the table initially. Also, in the error it shows are the server side query string parameters provided when performing server side processing with no colums, but instead %C for each column the was generated. I have been fighting with this for days. Please help.

Answers

  • TroyCroweTroyCrowe Posts: 8Questions: 1Answers: 0

    By the way, I am using version DataTables 1.10.15 as this application was built, and continues to be build, over many years. Also, as long as I do not use server side processing I am able to accomplish this without issue. The need for SSP is to provide the correct paging values. Another words, I am using sql paging and I am only loading the path length set of data. The paging needs to reflect the actual data size values.

  • aharro12aharro12 Posts: 10Questions: 1Answers: 0

    Post all your files into separate code blocks

    main file
    
    php file
    

    etc

  • TroyCroweTroyCrowe Posts: 8Questions: 1Answers: 0

    I have tricked it into loading the data but it is not doing it correctly. The paging is not working. It is being set to only the number of records instead of the total count. The number of records to display is 25 and the total count is 140. I am setting the paging in the following manner iTotalRecords = 140, iTotalDisplayRecords = 140

  • aharro12aharro12 Posts: 10Questions: 1Answers: 0

    Are you sending back the draw integer as sEcho?

  • TroyCroweTroyCrowe Posts: 8Questions: 1Answers: 0

    yes

  • TroyCroweTroyCrowe Posts: 8Questions: 1Answers: 0

    There is a problem with my tricking of the load. In my first load with the new columns I am initializing it without server side processing. This means all next processes, although they are able to reach the server, not having a problem with the path, there are not any query string values coming from the table. Therefore my pagesize, totalcount, sEcho, etc are empty. I believe this is why my paging is not working correctly even though I am feeding it data as listed above.

  • TroyCroweTroyCrowe Posts: 8Questions: 1Answers: 0

    It only has a problem with the path when I destroy the table, recreate the table with new columns, and then attempt to reinitialize with server side processing. Order matters. When I attempt to change the columns, then destroy the table, and then reinitialize the table It does not have a problem with the path and will hit the server, however the table columns do not get changed for some reason.

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

    Hi @TroyCrowe ,

    That ordering issue sounds odd. DataTables wouldn't have any knowledge of what was there before if you're reinitialising the table after destroying it. And it only accesses the path provided, it shouldn't matter what/how that path was created provided there's a listener on the other end.

    We're happy to take a look if you could isolate this into a small test case. Information on how to create a test case (if you aren't able to link to the page you are working on) is available here.

    Cheers,

    Colin

  • TroyCroweTroyCrowe Posts: 8Questions: 1Answers: 0

    I will not hit the listed for URL.
    Understand that $('#InvoiceProcessing').html(data.data); creates a new set of columns.

    var oTable.destroy();

                    $('#InvoiceProcessing').empty();
                    $('#InvoiceProcessing').html(data.data);
    
                    oTable = $("#InvoiceProcessing").DataTable({
                        jQueryUI: true,
                        pagingType: "full_numbers",
                        responsive: true,
                        "scrollX": true,
                        "bServerSide": true,
                        "sAjaxSource": "@Url.Action("GetInvoiceProcessing", "InvoiceProcessing")?clientId=" + cId + "&summaryDate=&processedDate=&accountNumber=&invoiceNumber=",
                        "bProcessing": true,
                        "destroy": true,
                        lengthMenu: [[25, 50, 100], [25, 50, 100]],
                        "autoWidth": true,
                        "aoColumns": data.data
                    });
    
  • TroyCroweTroyCrowe Posts: 8Questions: 1Answers: 0
    edited April 2019

    some reason the var oTable.destroy(); did not make it into the area above where code is listed. In the process above it is the "sAjaxSource" that is will not hit. Before $('#InvoiceProcessing').html(data.data); is will hit that path all day; which is the code that recreates the column set.

  • aharro12aharro12 Posts: 10Questions: 1Answers: 0

    You need to post your full code from all files. It is hard to get context on what you are achieving

This discussion has been closed.