Custom Edit and Remove using Datatable Editor is giving null or not an object exception
Custom Edit and Remove using Datatable Editor is giving null or not an object exception
PDas15
Posts: 4Questions: 0Answers: 0
Hi, I'm working on a project where I need to implemenet custom Edit & Remove functionality for datatables. I'm trying to incorporate Editor object to edit/remove rows from table. But while trying to submit for edit/remove I'm getting this js exception "'0.aoData[...].nTr' is null or not an object". Not sure what I'm missing here. Can anyone please advise?
Here is my jQuery code:
var wireTable;
var editor;
var wireDetails = "${ wireDetailList }";
$(document).ready(function(){
wireTable = $('#wiredtlstbl').dataTable({
"pagingType": "full_numbers",
"lengthMenu": [[10, 25, 50, -1], [10, 25, 50, "All"]],
"searching" : true,
"scrollY": 400,
"scrollCollapse": true,
"jQueryUI": true,
"processing": false,
"serverSide": false
//"ajax": "${pageContext.request.contextPath}/wireDetails/getWireDetails",
//"data": wireDetails
/* "columns": [
{ "data": null, "defaultContent": '', "orderable": false },
{ "data": "planNum" },
{ "data": "paymentMethod" },
{ "data": "wireReceivedTS" },
{ "data": "wireReceivedAmt" },
{ "data": "linkedIds" },
{ "data": "wireExptdDate" },
{ "data": "wireExptdAmt" }
] */
});
$('#wiredtlstbl tbody').on( 'click', 'tr', function () {
if ( $(this).hasClass('selected') ) {
$(this).removeClass('selected');
$('#edit').attr("disabled", true);
$('#delete').attr("disabled", true);
}
else {
wireTable.$('tr.selected').removeClass('selected');
$(this).addClass('selected');
$('#edit').attr("disabled", false);
$('#delete').attr("disabled", false);
}
} );
editor = new $.fn.dataTable.Editor( {
//ajax: "${pageContext.request.contextPath}/wireDetails/getWireDetails",
ajax: {
edit: {
type: 'PUT',
url: '${pageContext.request.contextPath}/wireDetails/getWireDetails'
},
remove: {
type: 'DELETE',
url: '${pageContext.request.contextPath}/wireDetails/getWireDetails'
}
},
table: "#wiredtlstbl",
display: 'envelope',
fields: [ {
label: "Plan Number :",
name: "planNum"
}, {
label: "Payment Method :",
name: "paymentMethod"
}, {
label: "Wire Received Date & Time :",
name: "wireReceivedTS"
}, {
label: "Wire Received Amount :",
name: "wireReceivedAmt"
}, {
label: "Link Id :",
name: "linkedIds"
}, {
label: "Wire Expected Date :",
name: "wireExptdDate"
}, {
label: "Amount Expected :",
name: "wireExptdAmt"
}
]
} );
$('#edit').click( function (e) {
alert('Clicked Edit');
//alert('wireDetails ---> '+ wireDetails);
e.preventDefault();
editor
.title( 'Edit Wire Detail' )
.buttons( { "label": "Update", "fn": function () { this.submit() } } )
.edit();
} );
$('#delete').click( function (e) {
alert('Clicked Delete');
//e.preventDefault();
editor
.title( 'Delete Wire Detail' )
.message( "Are you sure you wish to delete this record?" )
.buttons( {
label : "Delete",
fn : function () { alert('Deleting row'); this.submit(); }
} )
.remove('#wiredtlstbl tbody tr');
} );
/* $('#edit').on( 'click', function () {
editor
.buttons( {
label: "Save",
fn: function () { this.submit(); }
} )
.edit();
} ); */
});
This discussion has been closed.
Replies
Can you confirm what
getWireDetails
is returning when the submission is complete please? Does it confirm to the Editor client / server requirements?Allan
Hi Allan,
Thanks for your response. Well I've not used JSON object for getWireDetails. Actually that is already being painted from my Spring Controller as : model.addAttribute("wireDetailList", wireDetailList);
So I'm trying use the same view data and then edit/delete each row based on user action. I'm not sure whether the JSON is mandatory here but I think I need it more while submitting back the rows using edit/delete functionality. I'm kind doing it first so little uncertain on how to map these elements correctly. Please advise.
</script>
</body>
</html>
It is yes. The Editor manual describes the data sent to and from the server. If you are not using the libraries provided with the Editor package (PHP and .NET libraries available) then you will need to implement that protocol in your own scripts.
You could, if that is not possible, use the
ajax
option to perform a custom Ajax request which would give you the ability to submit the data and take returned data that you can then transform into the format that Editor requires before passing that data back into the callback functions.Allan
Thanks Allan for your response and suggestion. However I also modified my server-side code and created json object in controller class to pass to view as below:
Simultaneously I have modified my jsp code to read and process json object from controller as below. Surprisingly I'm getting exception like "Expected ';' " or "Unexpected String Constant" on the very first line of my json object while I'm trying to assign it to a JS variable to populate table data.
Can you please advise what's wrong I'm doing here?
Thanks,
Don't use
eval
! Use$.parseJSON
- http://api.jquery.com/jquery.parsejson/ .Beyond that, we would need to see what the
wireDetailsJson
value actually is.Allan
Thanks Allan for your valuable suggestion. Will try this out and let you know the results.