Can not implement Editor inline
Can not implement Editor inline
collinhunter
Posts: 5Questions: 1Answers: 0
I tried to implement inline editing of the datatable but I cannot select each cell - it doesn't seem to switch to a text box to edit
This discussion has been closed.
Answers
I keep getting: Unable to find row identifier For more information. I using datatables with SharePoint Online and rest calls to get the data. I'm also using 1.7.3.
RestUrl = appUrl + "_api/SP.AppContextSite(@target)/web/lists/getbytitle('Members')/items?$Select=Id,Title,bpAddress,bpAddress2,bpAddress3,bpCity,bpProvState,bpPostalZip,bpHomePhone,bpCellPhone,bpWorkPhone&$filter=" + $listofmembers + "&orderby=Title asc&@target='" + hostUrl.replace("#", "") + "'";
var oEditor = new $.fn.dataTable.Editor({
"ajax": data,
"table": '#BulkEditMembersTable',
"fields": [{
"label": "ID:",
"name": "Id"
}, {
"label": "Address:",
"name": "bpAddress"
}, {
"label": "Address 2:",
"name": "bpAddress2"
}, {
"label": "Address 3:",
"name": "bpAddress3"
}, {
"label": "City:",
"name": "bpCity"
}, {
"label": "Province/State:",
"name": "bpProvState"
}, {
"label": "Postal/Zip:",
"name": "bpPostalZip"
}, {
"label": "Home Phone:",
"name": "bpHomePhone"
}, {
"label": "Cell Phone:",
"name": "bpCellPhone"
}, {
"label": "Work Phone:",
"name": "bpWorkPhone"
}
]
});
Try moving
idSrc: 'Id',
from the Datatables config to the Editor. The Editor usesidSrc
.Kevin
Thanks that worked. Also I appended the following to the results2 json object so that it had a DT_RowId:
for (var i = 0; i < results2.length; i++) {
results2[i].DT_RowId = results2[i].Id;
}
Now the only issue is that when you click the cell, and enter a change, after you move to the next cell it reverses the changes. I assume that event would be the onBlur event (once leaving focus).
For example if City had Fredericton and you changed it to Toronto, when you click on a different field, it would revert back to Fredericton. I'm using REST calls so its a bit more work - I may have to put a button to save all the rows in the datatable and make a json call to update SharePoint.
Check out the editor example https://editor.datatables.net/examples/inline-editing/simple.html which will show you the results I'm seeing. Change a field and then lose focus. The change reverts back.
Are you retrieving and submitting the full row in the response for the inline edit?
This page shows the expected request and response:
https://editor.datatables.net/manual/server#Example-data-exchanges
Kevin