is changing the value of a cell possible?

is changing the value of a cell possible?

this_is_a_messthis_is_a_mess Posts: 3Questions: 1Answers: 0

hi,

it really surprises me that something so basic is so complicated in datatables. i checked a lot of the related examples, but the whole library is just a huge mess.

i am also very perplexed about the different methods of selecting a row. somehow there is an extension for this but there is also some internal support for selecting stuff. should i use the select extension?

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,540Questions: 1Answers: 10,476 Site admin

    I'm sorry to hear you don't like the API. The cell().data() method can be used to change a cell's value:

    $('#myTable').on( 'click', 'td', function () {
      table.cell( this ).data( 'Clicked' ).draw();
    } );
    

    i am also very perplexed about the different methods of selecting a row.

    The Select extension can be used for row selection. It provides the row().select() method.

    Allan

  • this_is_a_messthis_is_a_mess Posts: 3Questions: 1Answers: 0

    thank you very much for the answer. i just noticed how vague my question was. sorry for that!

    what i want specifically is changing a cell in the row that i selected.

    for example: i select a row; klick on a button; a function is called; a cell's value is changed.

    the problem is i don't know how to get to the cell. at first i have to get the selected row.

    i found some information on the internet and came up with the following line:

    table.row('.selected').cell(':eq(5)').data("1234").draw();

    or

    table.rows( { selected: true } ).cell(':eq(5)').data("1234").draw();

    the former is doing something, but in only changes the cell in the first row.

  • allanallan Posts: 63,540Questions: 1Answers: 10,476 Site admin
    Answer ✓

    The cell() method accepts both row and column selectors (the intersection of which of course is a cell):

    table.cell( '.selected', ':eq(5)' ).data( ... );
    

    See cell() for full details.

    Allan

  • this_is_a_messthis_is_a_mess Posts: 3Questions: 1Answers: 0

    thank you very much!

This discussion has been closed.