How to delete a row on client-side only with data from server-side?

How to delete a row on client-side only with data from server-side?

n3wb13n3wb13 Posts: 5Questions: 0Answers: 0
edited January 2012 in General
Hi there, I'm new to DataTables and I really need your help, here is my current script :

[code]
var oTable;
var giRedraw = false;

$(document).ready(function() {
$("#example tbody").click(function(event) {
$(oTable.fnSettings().aoData).each(function (){
$(this.nTr).removeClass('row_selected');
});
$(event.target.parentNode).addClass('row_selected');
});

$('#delete').click( function() {
var anSelected = fnGetSelected(oTable);
oTable.fnDeleteRow(anSelected[0]);
});

oTable = $('#example').dataTable({
"bProcessing": false,
"bServerSide": true,
"sAjaxSource": "data_json.php",
"sScrollY": "500px",
"bPaginate": false,
"bScrollCollapse": true,
"sPaginationType": "full_numbers"
});

});

function fnGetSelected( oTableLocal )
{
var aReturn = new Array();
var aTrs = oTableLocal.fnGetNodes();

for ( var i=0 ; i

Replies

  • allanallan Posts: 63,540Questions: 1Answers: 10,476 Site admin
    > I want to delete a row on the client-side only and leave the data from server-side unchanged

    You can't :-). This is intentional! You've got server-side processing enabled, so all the data is held at the server - thus if you want to remove a row, you need to remove it at the server-side - the client-side table simply reflects what is available on the server.

    For example, if you could delete rows client-side, then you did a sort, the server would sort the table with your deleted row still in it - which is wrong.

    So the data processing is either all client-side or all server-side.

    Allan
  • n3wb13n3wb13 Posts: 5Questions: 0Answers: 0
    Thank you for your answer. But in my case thing is a little bit different. I'm about creating a CSV editor in which, the user uploads his CSV to the server and gets the file parsed by PHP with some modifications and then later returned in JSON. DataTables has a plug-in to export the table as CSV that's why I need server-side processing at start-up only (I don't even need table sorting either). Do you have any suggestion for me please?
  • allanallan Posts: 63,540Questions: 1Answers: 10,476 Site admin
    Yes - don't use server-side processing! It sounds like you want to Ajax load and client-side process: http://datatables.net/release-datatables/examples/data_sources/ajax.html .

    Allan
This discussion has been closed.