Datatables send and load data not working in unfiltered datatable

Datatables send and load data not working in unfiltered datatable

wadeparallonwadeparallon Posts: 59Questions: 9Answers: 0
edited October 24 in DataTables 2

Link to test case: I cannot seem to figure out how to show a test case for my experience (ajax endpoints)
Description of problem:
I'm going to try to lay this out in the best way possible to understand.. I can't even figure out how to title this question right.

  1. I have a datatable that loads a list of projects
ajax : {
            url: "/Projects/GetProjects",
            type: "GET",
            dataType: "JSON"
        },

This table has a drawCallback that forces a reload on a summary table

        drawCallback: function(settings){
            if(DataTable.isDataTable("#SummaryDatatable")){
                console.log("Data Table drawCallback (data visible in API)");
                console.log(datatable.column(1, { filter: 'applied' }).data().flatten().toArray())
                summaryDatatable.ajax.reload();
            }
            
        }
  1. The summary table then POST data back to an API via AJAX with the current data from the Data table
ajax : {
            url: "/Projects/GetSummary",
            type: "POST",
            dataType: "JSON",
            data: function (d) {
                console.log("Summary Table Data Function (data to POST)");
                console.log(datatable.column(1, { filter: 'applied' }).data().flatten().toArray());
                d.projectIds =  datatable.column(1, { filter: 'applied' }).data().flatten().toArray();
            } 
        },

This currently WORKS in all scenarios EXCEPT the full unfiltered list. This includes the first load. The moment I apply any filter/search to Data table, this works flawlessly. If I clear all filters so that it shows nothing filtered in the info, the C# endpoint shows null for the data passed in.

The endpoint:

public IActionResult GetSummary(List<int> projectIds)

Relative screenshots:

Console log

C# Endpoint debugging with filtered results

C# Endpoint debugging with no filters

It might be a C# binding issue, but I've gone through every filter so each id would show (in case there was an id that wasn't an int) and I've parsed the objects from the console, all are the same and valid.

Is there something I'm missing in the documentation to handle unfiltered data? Even though I see it in the console just before asking for a reload... it fires, the end point is hit, but the data is missing.

Answers

  • wadeparallonwadeparallon Posts: 59Questions: 9Answers: 0

    Just to add to this, I know in C# I can handle the null and query differently in that endpoint to get the results I need, but I'm baffled to why this is happening from a Datatables perspective.

  • kthorngrenkthorngren Posts: 21,316Questions: 26Answers: 4,948

    Use the browser's network inspector tool to see the data sent in the ajax request. If the array of 1727 elements is sent in the request then the issue is in the server script. I'm not familiar with C# but if the json data is correct leaving the client then maybe its something to do with the GetSummary() method.

    Let us know what you find. Maybe someone has some ideas if it's in the server code. Stack Overflow might be a good resource to troubleshoot C# issues.

    Kevin

  • wadeparallonwadeparallon Posts: 59Questions: 9Answers: 0

    That's a good call. I can confirm the data is in the payload

    I suppose that lends to the idea the problem is on the endpoint side. I'll investigate further.

  • wadeparallonwadeparallon Posts: 59Questions: 9Answers: 0

    Found the answer. In C#, the ValueCountLimit for auto binding values on an endpoint is defaulted to 1024. My request had 1700+ values in it... I adjusted that max limit in the Program.cs file with to accept more values:

    builder.Services.Configure<FormOptions>(options =>
    {
        options.ValueCountLimit = 4096;
    });
    
  • kthorngrenkthorngren Posts: 21,316Questions: 26Answers: 4,948

    Great thanks for letting us know. Might help someone else.

    Kevin

Sign In or Register to comment.