How can I do datatable pagination with .net?

How can I do datatable pagination with .net?

tahaorhantahaorhan Posts: 23Questions: 3Answers: 0
edited October 2023 in Free community support

I am trying to paginate on the .net core side with jquery datatable, but in the ajax query it throws this error message "DataTables warning: table id=dtGeneralFundList - Ajax error. For more information about this error, please see http://datatables.net/tn/7" I leave my codes below, I am open to any advice, I look forward to your help.

var codeListTable = $('#' + tableId).DataTable({
                "processing": true,
                "serverSide": true,
                "ajax": {
                    "url": "FastFiltering",
                    "type": "POST",
                    "datatype": "json",
                },
                columnDefs: [
                    { "data": "Code", "name": "fundCode", "width": "0.2%", "targets": 0 },
                    { "data": "FundDtoValue.Name", "name": "fundName", "targets": 1 },
            });
public IActionResult FastFiltering(FastFilteringRequest model)
{
    try
    {
        result = _fundService.FastFiltering(fastFilteringParameters, userId).ToList();
        int pageSize = 0;
        var draw = Convert.ToInt32(Request.Form["draw"].FirstOrDefault() ?? "0"); // draw null ise varsayılan değeri 0 olarak ayarlar
        var start = Request.Form["start"].FirstOrDefault() ?? "0"; // start null ise varsayılan değeri 0 olarak ayarlar
        var length = Request.Form["length"].FirstOrDefault() ?? "10"; // length null ise varsayılan değeri 0 olarak ayarlar
        var sortColumn = Request.Form["columns[" + Request.Form["order[0][column]"].FirstOrDefault() + "][name]"].FirstOrDefault();
        var sortColumnDir = Request.Form["order[0][dir]"].FirstOrDefault();
        var searchValue = Request.Form["search[value]"].FirstOrDefault();
        pageSize = length !=null ? Convert.ToInt32(length) : 0;
        int skip = start !=null ? Convert.ToInt32(start) : 0;
        var data = (from resultPagingData in result select resultPagingData);
        if(!string.IsNullOrEmpty(sortColumn) && !string.IsNullOrEmpty(sortColumnDir))
        {
            data = data.AsQueryable().OrderBy(sortColumn + "" + sortColumnDir);
        }

        int totalRecord = data.Count();
        var cData = data.Skip(skip).Take(pageSize).ToList();

        var settings = new JsonSerializerSettings
        {
            ReferenceLoopHandling = ReferenceLoopHandling.Ignore
        };

        var jsonData = JsonConvert.SerializeObject(new
        {
            draw = draw,
            recordsFiltered = totalRecord,
            recordsTotal = totalRecord,
            data = cData
        }, settings);
        //j
        return Content(sonData, "application/json");
    }
}

Answers

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

    Have you followed the steps in the technical notes linked to in the error? That'll be the place to start. If so, what did you find? What does the server reply with?

    Colin

Sign In or Register to comment.