how to reload the dynamic datatable

how to reload the dynamic datatable

sumandahalsumandahal Posts: 1Questions: 1Answers: 0

i am having trouble to reload my datatable using ajax.reload function please have a look into my code and give some good suggestion.

This is my ajax code to pull the dynamic table

(function ($) {

$.fn.dataTableExt.oStdClasses.sPageButton = 'btn-flat small waves-effect';
var jTable;
var userTable;
/* -------- *
 * DOM LOAD *
 * -------- */
 $(document).ready(function() {

     $('#user_list_table').each(function() {
        jTable = $(this);

        userTable = jTable.DataTable({
            fnInitComplete: function(oSettings, json) {
                var jTableWrapper = jTable.parents('.dataTables_wrapper').eq(0);

                // Length
                jTableWrapper.find('.dataTables_length').addClass('input-field');
                jTableWrapper.find('.dataTables_length label select').prependTo(jTableWrapper.find('.dataTables_length'));
                jTableWrapper.find('.dataTables_length select').material_select();

                // Filter
                jTableWrapper.find('.dataTables_filter').addClass('input-field');
                jTableWrapper.find('.dataTables_filter').addClass('without-search-bar');
                jTableWrapper.find('.dataTables_filter label input').prependTo(jTableWrapper.find('.dataTables_filter'));
            },
            language: {
                "lengthMenu": "Per page: _MENU_",
            },
            dom: 
                "<'row no-gutter'" +
                "   <'col s12 m2'l>" +
                "   <'col s12 offset-m6 m4'f>" +
                ">" +
                "<''tr>" +
                "<'row no-gutter'" +
                "   <'col s12 m4'i>" +
                "   <'col s12 m8'p>" +
                ">",
            buttons: [
                'print'
            ],
            "ajax": base_url+"user/user_ajax_list",
            "columnDefs": [
                { className: "text-center", "targets": [ 0, 1, 2, 3 ] }
              ],
            "lengthMenu": [ [2, 4, 8,10,12,14,16,18,20, -1], [2, 4, 8,10,12,14,16,18,20, "All"] ],
            "pageLength": 10

                });
            });

 });

}(jQuery));

So how do i reload the table using ajax.reload function which is not working by doing this

// reload datatable

function reload_table()
{
    $('#user_list_table').DataTable().ajax.reload();
    alert('reload');
}
This discussion has been closed.