How would go about getting the edited value of a cell in a table for specific row?
How would go about getting the edited value of a cell in a table for specific row?
Link to test case:
Debugger code (debug.datatables.net):
function searchforfsrecords(){
var inactemp=$('#exemployee').val();
var curemp=$('#curemp').val();
var weekend=$('#weekend').val();
$('#tbledtchours').DataTable({
destroy:true,
paging:false,
scrollY:300,
searching:false,
bInfo:false,
ajax:{
url:'http://localhost:8081/timescalealpha/src/php/adminfs.php?inactemp='+inactemp+'&curemp='+curemp+'&weekend='+weekend+'',
dataSrc:''
},
columns:[
{title:'TimeIn:',data:'TimeIn',
mRender:function(data,type,row){
var editedvalue="";
return "<input type='textbox' value='"+data+"'>"
console.log(data);
},
},
{title:'InCodeb:',data:'InCode'},
{title:'TimeOut:',data:'TimeOut'},
{title:'OutCode:',data:'OutCode'},
{title:'Hours:',data:'Hours'},
{title:'Comments:',data:'Comments'},
{title:'Save:',data:'ID',
mRender:function(data,type,row){
return "<button class='btn btn-primary' type='submit' formaction='http://localhost:8081/timescalealpha/src/php/updatefsrecord.php?timein="+data+"'>Save</button>";
},
},
],
});
}
Error messages shown:
No error not doing as attended.
Description of problem:
I want to be able to click save button, then for lets say we click button row 1, I want to grab the edited value, let say TimeIn was 9:00AM but we changed it to 10:00AM. I want to pass 10:00AM, everything I have tried has only grab 9:00AM even tho I have change the value of the textbox on screen.
Any advice would be helpful.
Edited by Colin - Syntax highlighting. Details on how to highlight code using markdown can be found in this guide.
Answers
Because the DataTables doesn't know there's an
input
element in the cell, you need to get the node withcell().node()
, and then access it via that. Here's a working example (edit the top line and press the button) - the important bit of code is this:Colin
Would I then use closest to get just the row the button is click in? Otherwise would i have to code out each row that would be in the table?
I am getting closer, just need some clarfication:
How would i go about grabbing column TimeIn and TimeOut
Yes, you can use jQuery closest() to get the
td
andtr
of the clicked button. You can pass thetd
into thecell()
API. See thecell-selector
docs for more options.For example:
Kevin
I am having issue where when I click on the cell i get what's inside the input box, however when I click button I get nothing.
call function
Probably what you want to do is get the closest row. Use that along with the column index for the
cell()
API call. Like this:https://live.datatables.net/qiraqiko/1/edit
If you still need help then please update my example with your code so we can help debug.
Kevin