How to clear cell data so as not to pre-populate inline form?
How to clear cell data so as not to pre-populate inline form?
sjordan
Posts: 36Questions: 10Answers: 0
I have a table row like the following:
<tr id="task_19" role="row">
<td class="sorting_1">Task</td>
<td>Assignment</td>
<td>test <i class="fa fa-pencil"></i></td>
<td>Dec 17 2016</td>
<td>Please review<i class="fa fa-plus"></i></td>
</tr>
I'm doing inline editing and have an event handler like the following:
// Inline Edit Click-handler
$('#example1 tbody').on( 'click', 'td i', function (e) {
e.stopImmediatePropagation();
if (e.target.className == 'fa fa-plus'){
var cellData = table.cell( $(this).parent() ).data();
console.log(cellData); // I can confirm I can get the data (in this case 'Please review')
// the intent here is to clear the data so that it does not pre-populate the inline form when the cell is clicked
table.cell( $(this).parent() ).data(""); // THE ADDITION OF THIS LIKE CAUSES AN ERROR (see below)
}
editor.inline( $(this).parent(), {
onBlur: 'submit',
submit: 'changed'
});
});
How can I clear the data rendered initially in the inline form?
Error
Uncaught TypeError: Cannot read property 'contents' of undefined
at f.inline (datatables-editor.min.js:62)
at HTMLElement.<anonymous> (14:285)
at HTMLTableSectionElement.dispatch (jquery-1.10.2.js:5099)
at HTMLTableSectionElement.elemData.handle (jquery-1.10.2.js:4770)
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
I had a similar use case and solved it not by removing the data, but by clearing the input on open.
Note: this solution uses undocumented private editor properties that may change in the future.