setting the pagelenght variable in datatable ?

setting the pagelenght variable in datatable ?

SBD999SBD999 Posts: 36Questions: 1Answers: 0

Link to test case:
Debugger code (debug.datatables.net):
Error messages shown:
Description of problem:
I use the datable below.

When I launch my application I only have one with 10 registrations although I should be seeing a significant number of pages

How to change the pageLenght in al datatable?

$(document).ready(function () {
    $('#wSerieDatatable').dataTable({

        "processing": true,
        "serverSide": true,
        "filter": true,
        "ajax": {
            "type": "POST",
            "url": "/api/wSerie/doc",
           "datatype": "data.json"
        },
        "columnDefs": [{
            "targets": [0],
            "visible": true,
            "searchable": true
        }],
        "columnDefs": [{
            "targets": [1],
            "visible": true,
            "searchable": true
        }],
        "columns": [
            { "data": "id", "name": "Id", "autoWidth": true },
            {
                "data": "path", "name": "path",'render': function (data, type, row, meta) {
                    return '<a href="/api/wSerie/?relativePath=' + row.path + '" >' + row.path + '</a>';
                }
            },
           
            {
                "data": "name", "name": "Name", 'render': function (data, type, row, meta) {
                    console.log(row);
                    return '<a href="/api/wSerie/doc/' + row.id + '" >' + row.name + '</a>';
                }
            },
            { "data": "created", "name": "Created", "autoWidth": true }
        ]
    });
});

Replies

  • allanallan Posts: 61,723Questions: 1Answers: 10,108 Site admin

    That suggests to me that /api/wSerie/doc does not implement server-side processing. Is that correct? If so, remove the serverSide option from your initialisation options.

    Allan

  • kthorngrenkthorngren Posts: 20,309Questions: 26Answers: 4,769

    I only have one with 10 registrations although I should be seeing a significant number of pages

    Are you saying that the info element, ie Showing 1 to 10 of 57 entries, is showing only 10 entries but there should be more? Please provide more details of the problem.

    You have enabled server side processing which means the server script is responsible for calculating the total and filtered rows for the info element and paging buttons to display properly.

    How to change the pageLenght in al datatable?

    You can use the pageLength option to set the default page length. You can use page.len() API to programmatically change the page length.

    Kevin

  • SBD999SBD999 Posts: 36Questions: 1Answers: 0
    edited June 2022

    Sorry, I did not specify that's i work in aspnet core
    I made web api service as follow which is based on the jQuery DataTable object model.

      public async Task<DataTableResponse> GetDocumentStore(DataTableAjaxPostModel model)
            {
                    int? draw = model.draw;
                    int? start = model.start;
                    int? length = model.length;
                    string sortColumn = model.columns[model.order[0].column.Value].name;
                    string? sortColumnDirection = model?.order?[0].dir;
                    string? searchValue = model?.search?.value;
                    int pageSize = length != null ? Convert.ToInt32(length) : 0;
                    int skip = start != null ? Convert.ToInt32(start) : 0;
                    int recordsTotal = 0;
    
                    IQueryable<FilePath> query = from temppath in _context.FilePaths select temppath;
    
                    if (searchValue != null)
                    {
                        query = query.Where(m => m.Name.Contains(searchValue));
                    }
    
                    if (sortColumn != null && sortColumnDirection != null)
                    {
                      query = query.OrderBy(sortColumn + " " + sortColumnDirection);
                       }
    
                    var results = await query.Skip(skip).Take(pageSize).ToListAsync();
                    recordsTotal = results.Count();
    
                    DataTableResponse response = new DataTableResponse()
                    {
                        draw = draw.HasValue ? draw.Value : 0,
                        recordsFiltered = recordsTotal,
                        recordsTotal = recordsTotal,
                        data = results
                    };
    
                    return response;
                }           
    

    and in api web I do [HttpPost("doc")] and after I do /api/wSerie/doc
    All data is available in FilePath which is created in Sql View;

    I tried to disable serverSide and return this message

    So I think I have to enable serverSide. When is activate I see only ten records. My question is here?

  • SBD999SBD999 Posts: 36Questions: 1Answers: 0

    @kthorngren
    only 10 entries but there should be more?
    Yes, that's right. I should see 2000 records so 20 pages, if I selected 10 in entries!
    I see only 1 with 10records

Sign In or Register to comment.