DataTables row().remove() call not working
DataTables row().remove() call not working
I have a DataTable running from server side (with ajax pipeline). The display is fine and working as expected. In the last column of the table, there is a button which upon click will delete the corresponding row. This functionality is failing.
I have also tested with a single delete button from outside the table as described in https://datatables.net/examples/api/select_single_row.html, but that also does not work. The selected row gets deselected only in this case.
Highlights
* Javascript alerts within the onclick event is working
* The parent tr tag is getting correctly fetched
* table.row().remove().draw() not working
Sample table data:
<tbody>
<tr role="row" class="odd">
<td>1</td>
<td>গীতগোবিন্দ</td>
<td>Jaydev Goswami</td>
<td>1100</td>
<td><textarea class="senedtxt rdonly" onfocus="javascript: save_sentence(this, 26869, 13, false);" onblur="javascript: save_sentence(this, 26869, 13, true);">করেন যতন মোর রাখিবারে মন, তাঁহার সে খেলা কলি-কলুষ-নাশন</textarea></td>
<td><button class="jqbtn" onclick="javascript: return delocc(this,1);">delete</button></td>
</tr>
<tr role="row" class="even">
<td>2</td>
<td>তিতাস একটি নদীর নাম</td>
<td>Adwaita Mallabarman</td>
<td>1930</td>
<td><textarea class="senedtxt rdonly" onfocus="javascript: save_sentence(this, 11973, 7, false);" onblur="javascript: save_sentence(this, 11973, 7, true);">কোনো নৌকোয় মুর্শিদা বাউল গান হইতেছেঃ- এলাহির দরিয়ার মাঝে নিরাঞ্জনের খেলা, শিল পাথর ভাসিয়া গেল শুকনায় ডুবল ভেলা</textarea></td>
<td><button class="jqbtn" onclick="javascript: return delocc(this, 2);">delete</button></td>
</tr>
</tbody>
Javascript:
var stable;
$crp(document).ready(function() {
stable= $crp("#ssenttab").DataTable({
"processing": true, "serverSide": true, "responsive": dresp, "jQueryUI": true, "searching":false, "order": [],
"lengthMenu": [[5, 10, 15, 25, 50], [5, 10, 15, 25, 50]],
"searchDelay": 1000,
"columns": [
{"data": "serial", "orderable": false},
{"data": "title", "orderable": false},
{"data": "authors", "orderable": false},
{"data": "year"},
{"data": "sentence", "orderable": false},
{"data": "action", "orderable": false}
],
"ajax": $crp.fn.dataTable.pipeline({
"url": LexObj.auri+'panel/ajax/SpeechSentenceJSON',
"type": "POST",
"data": function(d){d.totalrec= snum; d.pskey=pskey;},
}),
"drawCallback": function(settings){
$crp(".jqbtn").button();
}
});
});
function delocc(delobj, spskey)
{
if(spskey>0)
{
if(confirm("Are you sure?"))
{
$crp.ajax({
'url': LexObj.auri+'/panel/ajax/SpeechSentDelete',
'data': {'dspsid': spskey},
'type': 'POST',
'dataType': 'jsonp',
'success': function(result){
if(result.status>0)
{
var partr= $crp(delobj).parents('tr');
alert(partr.attr('class'); // works and ouputs either 'odd' or 'even'
stable.row(partr).remove().draw(false); // does not work
alert('ok'); //works
}
}
});
}
}
return false;
}
Can anyone throw up some light? A ton of thanks in advance!!
Answers
Hi @pritwick
Can you say what you mean by "not working"? Are you seeing errors? We're happy to take a look, but as per the forum rules, please link to a test case - a test case that replicates the issue will ensure you'll get a quick and accurate response. Information on how to create a test case (if you aren't able to link to the page you are working on) is available here.
Cheers,
Colin
Thank you colin.
1. By 'not working' I mean nothing is happening. No errors/message in the console log too. Nothing happens at all when the button is clicked.
2. I'm working with jsp/servlet. So providing a test-case for the actual runtime environment will be tricky. Thogh I'm trying to setup one case for my problem. But it will take some time.
I'll reply to the chain once I post the test-case.
Since I was using pipelining, I needed to clear the pipeline before .draw() event.
The line:
should be
and this solved the problem.