Se pueden obtener todas las filas de datatables en formato json{key:value} ???

Se pueden obtener todas las filas de datatables en formato json{key:value} ???

Abraham_MAbraham_M Posts: 12Questions: 2Answers: 0

Se pueden obtener todas las filas de datatables en formato json{key:value} ???
Esto surge por que al querer extraerlo como array no los extrae en el formato correcto:

var datos_tabla = table.rows().data().toArray();
$("#id_data_table_carrito").val(JSON.stringify(datos_tabla) ) ;

Me da esto :

[[22, '5', 'pza', 'VARILLA 3/8', '158.879', '794.39', "<i class='fa fa-check-square-o fa-lg' aria-hidden='
true'></i>"], [30, '10', 'kg', 'ALAMBRON', '26.121', '261.21', "<i class='fa fa-check-square-o fa-lg' aria-hidden='true'></i>"], [31, '7', 'pza', 'ARMEX 15-20', '160',
'1120', "<i class='fa fa-check-square-o fa-lg' aria-hidden='true'></i>"], [34, '15', 'bulto 50 kg', 'CEMENTO', '165', '2475', "<i class='fa fa-check-square-o fa-lg' ari
a-hidden='true'></i>"]]

pero el primer campo no lo toma como string por lo que al querer volverselo a meter a una datatables da error
Alguna otra alternativa???
Gracias de antemano

Answers

  • kthorngrenkthorngren Posts: 20,309Questions: 26Answers: 4,770

    All rows of datatables can be obtained in json{key:value} format??? This arises because when you want to extract it as an array you do not extract them in the correct format:

    The rows().data() will get the rows in the format that you initialized Datatables with. If you have a DOM sourced table this will default to the rows being arrays instead of objects. See the Data docs for details.

    But the first field does not take it as a string so wanting to put it back into a datatables gives error Some other alternative??? Thanks in advance

    See my answer in your other thread.

    Kevin

Sign In or Register to comment.