Quantcast
Channel: Recent Discussions — DataTables forums
Viewing all articles
Browse latest Browse all 82244

Looking for code example to 'splice' row into table.

$
0
0

I can't seem to figure out how to insert a row into a table using the splice API function. It seems very simple, but I must be doing something fundamentally wrong. My code is something like this:

$(document).ready(function () {
    
    $('#example').DataTable( {
        "lengthMenu": [ [4, 10, 25, -1], [4, 10, 25, "All"] ],
        "ordering": false,  // don't allow columns to be sorted.
        select: true,  // enable the (row) Select module functionality.
        select: 'single',  // only allow one row to be selected at a time.
        dom: 'B<"clear">lftip',  // https://datatables.net/reference/option/dom
        buttons: [ ]  // no custom buttons needed, (but this line is required).
    } );

    var table = $('#example').DataTable();

    table.button().add( 1, {
        action: function ( e, dt, button, config ) {
            var idx = dt.row('.selected').index();
            dt.splice(idx, 0, <something>);  // <--------
            dt.draw();
        },
        text: 'Insert row'
    } );
});

I've tried all kinds of things for <something>, and many different ways to invoke the splice() call, but nothing seems to work. To eliminate the <something> issue, I even tried hard-coding a 'remove' using dt.splice(1,0);, but that doesn't even work.

In another button handler (not shown), I implemented a row 'remove', and that works flawlessly:

dt.rows('.selected').remove().draw();

If someone could point me to a simple splice() example or point to an improper construct in my code, I would much appreciate it!


Viewing all articles
Browse latest Browse all 82244

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>