how to initialize searching and paging options for datatable?

how to initialize searching and paging options for datatable?

profoundhypnoticprofoundhypnotic Posts: 12Questions: 5Answers: 0
edited November 2022 in Free community support

when I create a datatable like in the link below, I do not get the searching, paging, options that come with the basic initialization of a dataTable. But if I instead, initialize the datatable and put it in the success function of an Ajax call then I get the searching and paging options. I don't think I can make a test case for this because of the ajax call, it just wouldn't run in the test case (I think) so I attached a screenshot of the DataTable being called from the success function of $.ajax({}).

Here is the code for initializing a DataTable in success of Ajax call used in the above screenshot. without a searching or paging option specified, these options are shown on the datatable (screenshot)

$.ajax({ 
type: 'post', 
url: 'test.php', 
dataType: 'json', 
data: $('#filters').serialize(), 
success: function(data){ 
     train = $('#GA').DataTable({ 
           data: data, 
           columns: [ 
               { data: 'NAME'}, 
               { data: 'ROOF_ASSEMBLY'}, 
               { data: 'DOOR_ASSEMBLY'}, 
               { data: 'WALL_ASSEMBLY'}, 
               { data: 'PLENUM_ASSEMBLY'}, 
               { data: 'TANK_BASE_ASSEMBLY'}, 
               { data: 'FINAL_ENCLOSURE_ASSEMBLY'}, 
               { data: 'ENCLOSURE_ELECTRICAL'},
               { data: 'SUBPANEL_ASSY_WIRING_ELECTRICAL'}, 
               { data: 'PREP_ELECTRICAL'}, 
               { data: 'TANK_BASE_ELECTRICAL'},
               { data: 'FINAL_ASSEMBLY_ELECTRICAL'}, 
               { data: 'CRANE_OPERATION_SAFETY'}, 
               { data: 'RESPIRATORY_PROTECTION'}, 
               { data: 'HEAVY_LIFTING'}, 
               { data: 'FORKLIFT_CERTIFIED'}, 
               { data: 'LOCKOUT_TAGOUT_CERTIFIED'}, 
               { data: '5S_TRAINING'}, 
               { data: 'CRANE_SLING_TRAINING',render: function (data,type,row,meta) {return data+'   <i class="edit fa fa-pencil"</i>';}} ],
       pageLength: 50, 
       scrollX: true 
}); 
} 
});

test case: http://live.datatables.net/niyojote/1/ - searching and paging options missing.

Answers

  • profoundhypnoticprofoundhypnotic Posts: 12Questions: 5Answers: 0

    I can't find the forum post now but I read that with the above approach searching must be handled on the server side. if someone can confirm, that'd be cool but that's how it appears to me.

  • kthorngrenkthorngren Posts: 21,299Questions: 26Answers: 4,945

    You have dom: 't', which is going to show only the table. See the dom docs for details. Remove the option, like above, and you will have searching, etc.
    http://live.datatables.net/niyojote/2/edit

    Kevin

  • kthorngrenkthorngren Posts: 21,299Questions: 26Answers: 4,945

    I read that with the above approach searching must be handled on the server side.

    No, searching will take place client side unless you enable server side processing with the serverSde option.

    Kevin

Sign In or Register to comment.