adding and removing row by id ?

adding and removing row by id ?

yarekyarek Posts: 5Questions: 0Answers: 0
edited November 2013 in General
My table reflects users.

I can add some rows (adding some html), but I cannot affect an unique id to them.
My goal would be to haev functions such as:

function addUser(username) {
// add a row() whose id=username
}

function removeUser(useranme) {
// remove a row () whose id=username
}

Any clue to acheieve that ?

Thanks

Replies

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    This will be easier with 1.10 (it has these features available if you want to try it), where you can do something like:

    [code]
    var table = $('#myTable').DataTable();

    // Remove a row by Id:
    table.row('#myId').remove().draw();

    // Likewise to add a new row:
    table.row.add( $('...') ).draw();
    [/code]

    Among other options. It is possible in 1.9- but a fair bit more complicated.

    Allan
  • yarekyarek Posts: 5Questions: 0Answers: 0
    Hi: where can I download it from ?
    I don't see any available links for 1.10.

    regards
  • yarekyarek Posts: 5Questions: 0Answers: 0
    I found it on gitHub

    $('#tableUsers').dataTable().row.add( ('zazaza') ).draw();

    Uncaught TypeError: Cannot call method 'add' of undefined
  • rbormanrborman Posts: 5Questions: 0Answers: 0
    To get (pre) beta version 1_10_WIP, go to Github, switch to the 1_10_WIP branch and download the ZIP file. The unpacked directory contains the media directory with the .js and .css files, as well as examples.
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    > $('#tableUsers').dataTable(

    Note the uppercase `D` in my example - `$('#tableUsers').DataTable(` . The uppercase version gives yo the DataTales API object.

    Allan
This discussion has been closed.