How to make editable columns with separate JSON source (one editable on is not)
How to make editable columns with separate JSON source (one editable on is not)
Link to debug information: http://debug.datatables.net/apavad
Hi, I'm trying to use two different SQL sources with datatables (both as JSON format). The first source gives the main content of the datatable. This content cannot and will not be editable - always fixed! The second source are ment to give some additional columns where the user have his/hers own data with edit possibilities. Both datasets have a common id-key as a 10 digit number.
The table can list all the data from the first dataset correctly, but when I try to activate EDITOR I get an error: Requested unknown parameter: 'Sas_ArkivsakID' for row 646, column1.
In the EDITOR listin below you will see that I have only defined the columns whic have relevance to the "updateble" columns in the second dataset.
I have tried to look into the suggested documentation and examples, but with no luck so far - so any suggestions would be appreciated as I have been working with Datatables for 3-4 years now and I find it to be an excellent product which I now will extend by bying the EDITOR (when I've got it to work )
The Datatable definition seem work correctly:
var table = $('#websakListe').DataTable( {
"autoWidth": false,
dom: 'Bfrtip',
buttons: [
'colvis',
'excel',
'print',
'pdf'
],
"lengthChange": false,
"select": false,
"ajax": "json_saksliste2.asp?sBehID=" + sBehID,
"language": {
url: '/local/no_NO.txt'
},
"columns": [
{
"className": 'details-control',
"orderable": false,
"data": null,
"defaultContent": ''
},
{ "data": "Sas_ArkivSakID" },
{ "data": "Sas_Sakstittel" },
{ "data": "Ssp_PartsForholdID" },
{ "data": "Sas_KategoriID" },
{ "data": "Ssp_Navn" },
{ "data": "Sas_SisteDokDato" },
{ "data": "Sas_Status" },
{ "data": "Navn" },
{ "data": "Loginn" },
{ "data": "fldEgenStatus", editField: "fldEgenStatus" },
{ "data": "fldEgenPrioritering", editField: "fldEgenPrioritering" },
{ "data": "fldProsessFremdrift", editField: "fldProsessFremdrift" },
{ "data": "fldStatuskommentar", editField: "fldStatuskommentar" },
{ "data": "fldFristDato", editField: "fldFristDato" }
],
select: true,
buttons: [
{ extend: 'create', editor: editor },
{ extend: 'edit', editor: editor },
{ extend: 'remove', editor: editor }
],
"columnDefs": [
{"className": "dt-center", "targets": [ 3,4,6,7 ]},
{
"targets": [ 6 ],
"visible": true,
"searchable": true,
"render": $.fn.dataTable.render.moment( 'DD-MM-YYYY' )
},
{
"targets": [ 7 ],
"visible": false,
"searchable": false
},
{
"targets": [ 9 ],
"visible": false
},
{
"targets": [ 14 ],
"visible": true,
"null": true,
"searchable": true,
"render": $.fn.dataTable.render.moment( 'DD-MM-YYYY' )
}
]
} );
The EDITOR - I'm not shure what I do Wrong:
var editor = new $.fn.dataTable.Editor( {
"ajax": "update.asp?sBehID=" + sBehID,
"table": '#websakListe',
"dateImage": "ressurser/calendar.gif",
"idSrc": "Sas_ArkivSakID",
"fields": [
{ label: 'Egen status', name: 'fldEgenStatus' },
{ label: 'Egen prioritering', name: 'fldEgenPrioritering' },
{ label: 'Prosess fremdrift', name: 'fldProsessFremdrift' },
{ label: 'Status kommentar', name: 'fldStatuskommentar' },
{
label: 'Frist dato:',
name: 'fldFristDato',
type: 'date',
def: function () { return new Date(); },
dateFormat: 'd/m/yy'
}
]
} );
The returned AJAX JSON:
{
"data":[
{
"DT_RowId":"2016004427",
"fldEgenStatus":"",
"fldEgenPrioritering":"",
"fldProsessFremdrift":"",
"fldStatuskommentar":"",
"fldFristDato":"2017-10-10 "
}
]
}
This question has accepted answers - jump to:
Answers
Hi,
Thanks for the details! The issue is that the data set being returned by
"update.asp?sBehID=" + sBehID
is incomplete for the row. Editor doesn't (currently) merge the values that already exist on the client-side with those new values from the server. Instead, it expects the data for the whole row to be returned.Is that something you can modify your server-side environment to do? If so, I would recommend doing it that way. If that isn't possible, we can use the events that Editor triggers to merge the data - let me know if you want to take that route and I'll write an example based on your above showing how it might be done.
Regards,
Allan
Thanks - OK I understand and I did think in that direction as well, bu I wasnt shure if I could say that the static columns could be ignored.
I will probably be able to solve this serverside - I'll get on the job tomorrow
Let me know how you get on with it!
Regards,
Allan
Hi, regarding this issue I decided to make the dataset complete and merged from the backend. It is working fine for me!
Hi, just to put this issue to rest - I solved this by changing my JSON serverside so that I was able to merge data from two databases independently, and also to update only one of them as the othe is read only.