get selected item value with javascript/ajax sourced data

get selected item value with javascript/ajax sourced data

t0n1zzt0n1zz Posts: 32Questions: 19Answers: 0

so i have this code that use for getting value from datatable row and it works fine is my datatable source data is from DOM

var id = $.map(table.rows({ selected: true }).data(),function(item){
     return item[3];
});

but after i change my datatable by using javascript/ajax sourced data, it just return nothing...

This question has an accepted answers - jump to answer

Answers

  • rf1234rf1234 Posts: 2,808Questions: 85Answers: 406

    this works with Ajax sourced tables:

    var selected = yourTable.row( {selected: true} ); 
    if (selected.any()) {
      //do something with:
        selected.data().YourField(s)
    }
    
  • allanallan Posts: 61,740Questions: 1Answers: 10,111 Site admin
    Answer ✓

    but after i change my datatable by using javascript/ajax sourced data, it just return nothing...

    Are you using columns.data to tell DataTables to use object based data instead of array based? If so, you'd need to use return item.myProperty;.

    Allan

This discussion has been closed.