Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Update a row using DataTable()

I would like to know the correct way to update/redraw a table row using the new API. Old questions suggest table.fnUpdate. Should I still be using the old API for this?

The new API tells me nothing about updating rows.

Thanks in advance!

like image 951
filur Avatar asked Jun 08 '15 13:06

filur


People also ask

How to update and delete rows in a DataTable?

Update and Delete Rows in a DataTable 1 For Each dr As DataRow In ds.Tables (0).Rows 2 If (dr ("Name") = "Mahesh" Then 3 dr.Delete () 4 End If 5 ds.Tables (0).AcceptChanges () 6 Next

What is an alternative to row()data()?

An alternative to row ().data () is to use row ().invalidate (). This discussion has been closed.

How can I update a row by some identifier?

So in order to update a row I wanted to identify the row to be updated by some identifier may be a row id and perform the update of the coumns in that specific row. How can I achieve this. I tried fnupdate but seems to have depricated. You can update row data with row ().data ().

Why is newdata() not working?

For setting the data newData has to either be an array or object, you need to make sure it matches the type of data you've used for the table. If this doesn't match then it wont work. An alternative to row ().data () is to use row ().invalidate ().


1 Answers

if you have set specific id attribute for your rows with Datatable method , then you can select with :

table.row('#row_'+ idRow).data(rowData).draw()

Because generation of id attributes must be like this to be selected by after :

Ex id 3:

   // In php : push the key 'DT_RowId' foreach row  
      foreach ($items as $item) {
           $item['DT_RowId'] = 'row_' . $id;
      }

After you have specific id and you can select easily for an update :

 <tr id="row_3" class="...">
    ....
    </tr>
like image 84
Olivier Mongeot Avatar answered Oct 09 '22 07:10

Olivier Mongeot