datatable displayStart not working

datatable displayStart not working

Sathish123Sathish123 Posts: 2Questions: 1Answers: 0
edited December 2015 in Free community support

Hi,

In the application we have a jQuery datatable and inside the table there is a dropdown (action). On select of any action drop down I am setting the displayStart and iDisplayLength in the action class. But for some reason the page numbers are getting reset to 1 and some times it is on the correct page. For example, displayStart =1 to displaylength=24 for page 1, displayStart=25 to displaylegth=49 for page 2 and goes on. If I am on page 2 select action dropdown then it kicks me back to page 1.
Any idea what am I doing wrong?

Below is the partial code snippet because of the size limit on this post.

    function loadDataTable(){
           orderPendingCreditApprovalTable=$("#orderPendingCreditApprovalTable").DataTable({
                autoWidth:false,                
                processing: true,
                serverSide: true,
                deferRender: true,
                pagingType: "full_numbers",
                dom: '<"top"i<"toolbar">p<"clear">>rt<"bottom"ip<"clear">>',
                columns:<%=creditActionForm.getColumnHeader()%>,
                displayStart : <%=creditActionForm.getDataTableStart()%>,
                iDisplayLength: <%=creditActionForm.getDataTableLength()%>,
//              lengthChange:false,
                ajax: {
                    url: '/pcs/ordersPendingCA.do',
                    type: 'POST',                   
                    data:function(data){
                        var object="";
                        if(orderPendingCreditApprovalTable !=null){
                            object+=orderPendingCreditApprovalTable.$('input,select').serialize();
                        }
                        object+="&json="+JSON.stringify(data);
                        object+="&action=dataTable";
                        return object;
                    }
                },
                order: [[ <%=creditActionForm.getDataTableOrderColumn()%>, "<%=creditActionForm.getDataTableOrderDirection()%>" ]],
                columnDefs: [
                             {
                                 render: function (data,type,row,meta) {
                                     var root='<%=GlobalConstants.APPLICATION_ROOT%>';
                                     var link='';
                                     if(row.accountType === 1 ){
                                         link=root+"/findBusinessAccount.do?searchBy=2&searchAccountKey="+data+"&pageFrom=ordersPendingCA";
                                     }else if(row.accountType === 2){
                                         link=root+"/findConsumerAccount.do?searchAccountKey="+data+"&pageFrom=ordersPendingCA";
                                         
                                     }
                                    return "<a class='fctn' href='"+link+"'>"+data+"</a>";
                                 },targets: 0
                             },
                                }

Edited by Allan - Syntax highlighting. Details on how to highlight code using markdown can be found in this guide.

Answers

  • allanallan Posts: 63,353Questions: 1Answers: 10,444 Site admin

    We would need a link to a page showing the issue so it can be debugged please.

    f I am on page 2 select action dropdown then it kicks me back to page 1.

    I don't understand this bit I'm afraid - I don't see any API calls above. Are you using the DataTables API?

    Allan

  • Sathish123Sathish123 Posts: 2Questions: 1Answers: 0

    Unfortunately I cannot share the url, since it's an intranet application. Yes I do use the datatable api.

    Basically the problem is with the paging.

    Showing 2,065 to 252 of 252 entries.
    This is not working even when I set the displayStart : <%=creditActionForm.getDataTableStart()%>,
    iDisplayLength: <%=creditActionForm.getDataTableLength()%>,

    I am setting the values for displayStart to 0 and iDisplayLength to 24 from the java class. I verified this is being set. But still in the UI, the start and length values are not reset. The paging is not getting updated for the first time. From the next time the paging works fine. Not sure what causes the issue for the first time.

  • glendersonglenderson Posts: 231Questions: 11Answers: 29

    "Showing 2,065 to 252 of 252 entries"

    2,065 is the value being returned by the json from '/pcs/ordersPendingCA.do'

    In your code, you need to query and calculate the number of total records and the number of filtered records.

    iTotalRecords = the Total number of records in your database.
    iTotalDisplayRecords = the Total number of records after applying the passed filters

    Don't forget that it's your code that also needs to read the start and length parameters from the get or post variables to determine what the sql limit clause is going to be.

    I typically need to perform 3 queries in server side processing
    1 - How many total records are there.
    2 - How many filtered records are there
    3 - Return length number of records from the filtered recordset starting at the start value.

This discussion has been closed.