3

I am using a jQuery DataTables style for the responsive layout, but when I use javascript to append <td>Mycode</td> in the table, then the dataTables style not working, any idea?

2
  • Can you share your code here? if you want to add a new Data row in Jquery dataTable you can use datatable's row.add method Commented Apr 28, 2016 at 7:35
  • Welcome to SO. Please visit the help center and take the tour to see what and how to ask here. HINT: Post code and effort Commented Apr 28, 2016 at 7:40

2 Answers 2

1

DataTable does not work in append in javascript, because after calling .DataTable method our append method calls. If you debug your javascript code, then you will find that .DataTable call before .append. Check our table body, it does not render at time when .DataTable calls. So write .DataTable method after .append method.

$('#grdWrkServiceEntry').append(tableBody);
$('#grdWrkServiceEntry').DataTable();

I also faced the same problem, but now it is resolved.

Sign up to request clarification or add additional context in comments.

Comments

0

Here We go:

In documentation I find it:

New rows can be added to a DataTable very easily using the row.add() API method. 

Try add new row as this like code:

function row.add() can help you;)

    $(document).ready(function() {
        var t = $('#yourDataTableId').DataTable();
        var counter = 1;

        $('#addRow').on( 'click', function () {
            t.row.add( [
                counter +'.1',
                counter +'.2',
                counter +'.3',
                counter +'.4',
                counter +'.5'
            ] ).draw( false );

            counter++;
        } );


        $('#addRow').click();
    } );
<button id="addRow">Add new row</button>

Hope it helps;)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.