Infinite Scroll and Server Side Processing with Length

Infinite Scroll and Server Side Processing with Length

JoshuaTJoshuaT Posts: 1Questions: 1Answers: 0

I am trying to get infinite scrolling to work with server side processing. With the current settings below a POST request is made to the API, but the length is set to -1 and so the API will not respond with all data (setup to not respond in such inefficient ways). When paging is on the length property is populated correctly, but when off and scroll is on the length is always -1.

Is there a way of only getting the data that can be displayed on the table - for example I can see 10 rows so I only request 10 or 20 (set length to 10)?

var table = $('#usersTable').DataTable({
      //data: this.users,
      serverSide: true,
      ajax: {
        url: "http://localhost:8282/user/paged/",
        type: "POST"
      },
      scrollY: $(window).height() - $('#header').height() - 224, 
      scroll: true, 
      deferRender: true,
      sDom: "Zlfrtip",  
      info: false,
      paging: false,
      //pageLength: 2,
      columns: [
        { "data": "id" },
        { "data": "name" }
      ],
      initComplete: function (settings) {
        // Move the search outside of where it is place by default ...
        var dataTableFilterToMove = $('.dataTables_filter').detach();
        var dataTableFilterMoveTo = $('#dataTableSearch');
        dataTableFilterToMove.appendTo(dataTableFilterMoveTo);
      },
      colReorder: {
        iFixedColumns: 1,
        fnReorderCallback: function () {
        }
      },
      colResize: {
        resizeCallback: function (column) {
        }
      },
      language: {
        search: "",
        searchPlaceholder: "Search Users ..."
      }
    });

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,226Questions: 1Answers: 10,416 Site admin
    Answer ✓

    DataTables doesn't support inifite scrolling I'm afraid.

    but the length is set to -1

    Yes, you have disabled paging, so all records would be needed to display the table.

    Allan

This discussion has been closed.