Update cell with value from javascript
Update cell with value from javascript
I'm trying to add "updated_by" as hidden column that pulls a value from a div ($('#fullName').innerHTML;) when the row is updated.
I tried adding
"type": "hidden", and "visible": "false" to the updated_by field but it was still showing in the front end.
To get the value from the div in the "updated_by" column I tried adding a render function to the field, but it was showing in all the rows and not in the one that was just edited.
Below my current code.
`(function($){
$(document).ready(function() {
var editor = new $.fn.dataTable.Editor( {
ajax: 'php/table.MyTable.php',
table: '#MyTable',
fields: [
{
"label": "full_name:",
"name": "full_name",
"type": "display",
},
{
"label": "phone_number:",
"name": "phone_number",
"type": "display"
},
{
"label": "comments:",
"name": "comments",
},
{
"label": "updated:",
"name": "updated_by"
}
]
} );
$('#MyTable').on( 'click', 'tbody td:not(:first-child)', function (e) {
editor.inline( this, {
onBlur: 'submit'
} ); } );
var table = $('#MyTable').DataTable( {
dom: 'Bfrtip',
ajax: 'php/table.MyTable.php',
columns: [
{
"data": "full_name"
},
{
"data": "phone_number"
},
{
"data": "comments"
},
{
"data": "updated_by",
}
],
select: false,
lengthChange: false,
buttons: [
],
pageLength: 20,
} );
} );
}(jQuery));
`
Any help will be appreciated.
This question has accepted answers - jump to:
Answers
You could do something like this here. In that example, it's changing the case of a string before submitting, you could use the same structure but add your div value into the field prior to the submission,
Colin
Thanks @colin The following did the trick:
Still trying to hide the column.
Ah sorry, I missed that. To hide it in the table, you can use
columns.visible
, and to remove it from the Editor form, you can do something like:Colin
Thanks again Colin. I managed to get it working with
columnDefs: [ { "visible" : false, "targets": 4, "searchable": false} ]
As for some reason it was not working with
editor.field('updated_by').hide();
Yep,
field().hide()
is only for the Editor form,columns.visible
is for the table itself. Glad all sorted,Colin