简体   繁体   中英

jQuery Datatable sort issue

I am using the Datatable plugin

http://www.datatables.net/examples/basic_init/zero_configuration.html

to populate the table I use jquery .html() function and pass the table content to it .

the problem is after the data is appended to the table all the sort , paginate and search functions are not working anymore , each change on these removes the data from the table .

can anyone help me with this problem please ?

thank you

You can use an alternate method to add the data to the table using the row.add functionality of the Datatable. Here's the code:

JQuery

$(document).ready(function() {
    var t = $('#example').DataTable();

    $('#addRow').on( 'click', function () {
        t.row.add( ['a','b','c','d','e'] ).draw();
    } );
} );

HTML

<button id="addRow">Add</button>
<table id="example" class="display" cellspacing="0" width="100%">
        <thead>
            <tr>
                <th>Column 1</th>
                <th>Column 2</th>
                <th>Column 3</th>
                <th>Column 4</th>
                <th>Column 5</th>
            </tr>
        </thead>
</table>

You can keep the visibility of the table hidden during the start and once the data is populated, show the table.

JSFiddle: http://jsfiddle.net/ntgm9rde/1/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM