Datatable doesn't refresh
Datatable doesn't refresh
sanderk
Posts: 26Questions: 4Answers: 1
I have a page with a parent child table. However the child table doesn't refresh and the id is not passed to the child table editor. I cannot find the problem as there are no errors
JavaScript
$(document).ready(function () {
var huurderEditor = new $.fn.dataTable.Editor({
ajax: {
url: "/Gebouwen/HuurdersTable",
type: "POST",
data: function (d) {
d.GebouwID = currentGebouwID
}
},
table: "#huurdersTable",
fields: [{
label: "Naam huurder:",
name: "NaamHuurder"
}, {
label: "Huisnummer:",
name: "Huisnummer"
}, {
label: "Startdatum contract:",
name: "StartDatumContract",
type: "datetime",
format: 'DD-MM-YYYY'
}, {
label: "Einddatum contract:",
name: "EindDatumContract",
type: "datetime",
format: 'DD-MM-YYYY'
}, {
label: "Opzegtermijn (in maanden):",
name: "Opzegtermijn"
}, {
label: "Parkeerplaatsen:",
name: "Parkeerplaatsen"
}, {
label: "Huur Verlengperiode:",
name: "HuurVerlengperiode"
}, {
label: "Opmerkingen:",
name: "Opmerkingen",
type: "textarea"
}, {
label: "Aantal m2 VVO:",
name: "AantalM2VVO"
}, {
label: "Aantal m2 BVO:",
name: "AantalM2BVO"
}
],
i18n: {
create: {
button: "Nieuw",
title: "Nieuwe invoer",
submit: "Opslaan"
},
edit: {
button: "Bewerken",
title: "Bewerk record",
submit: "Opslaan"
},
remove: {
button: "Verwijder",
title: "Verwijder",
submit: "Verwijder",
confirm: {
_: "Weet u zeker dat u %d records wilt verwijderen?",
1: "Weet u zeker dat u dit record wilt verwijderen?"
}
},
error: {
system: "Er is een systeemfout opgetreden. Neem aub contact op met de ontwikkelaar."
},
datetime: {
previous: 'Vorige',
next: 'Volgende',
months: ['Januari', 'Februari', 'Maart', 'April', 'Mei', 'Juni', 'Juli', 'Augustus', 'September', 'Oktober', 'November', 'December'],
weekdays: ['Zo', 'Ma', 'Di', 'Wo', 'Do', 'Vr', 'Za']
}
}
});
var huurderTable = $('#huurdersTable').DataTable({
dom: "Bfrtip",
ajax: {
url: "/Gebouwen/HuurdersTable",
type: "POST",
data: function (d) {
d.GebouwID = currentGebouwID
}
},
serverSide: true,
order: [[1, 'asc']],
pageLength: 10,
language: {
url: '/json/datatables-dutch.json'
},
columns: [
{ data: "NaamHuurder" },
{ data: "Huisnummer" },
{ data: "StartDatumContract" },
{ data: "EindDatumContract" },
{ data: "Huurders.Opzegtermijn" },
{ data: "Huurders.Parkeerplaatsen" },
{ data: "Huurders.HuurVerlengperiode" },
{ data: "Huurders.AantalM2VVO" },
{ data: "Huurders.AantalM2BVO" },
{ data: "Huurders.Opmerkingen" }
],
select: {
style: 'single'
},
buttons: [
{ extend: "create", editor: huurderEditor },
{ extend: "edit", editor: huurderEditor },
{ extend: "remove", editor: huurderEditor }
]
});
huurderTable.buttons().container()
.appendTo($('.col-md-6:eq(0)', huurderTable.table().container()));
// #endregion
// #region HuurdersExtraEigenschappen
var huurderExtraEigenschappenEditor = new $.fn.dataTable.Editor({
ajax: {
url: "/Gebouwen/HuurderExtraEigenschappenTable",
type: "POST",
data: function (d) {
var selectedHuurderrow = huurderTable.row({ selectedHuurderrow: true });
if (selectedHuurderrow.any()) {
d.HuurderId = selectedHuurderrow.data().Huurders.id;
}
}
},
table: "#huurderExtraEigenschappenTable",
fields: [{
label: "Ingangsdatum:",
name: "HuurderExtraEigenschappen.Ingangsdatum",
type: "datetime",
format: 'DD-MM-YYYY'
}, {
label: "Eigenschaptype:",
name: "HuurderExtraEigenschappen.HuurderEigenschapTypeId",
type: "select",
placeholder: "Selecteer een eigenschaptype"
}, {
label: "Waarde:",
name: "HuurderExtraEigenschappen.Waarde"
}, {
label: "Huurder:",
name: "HuurderExtraEigenschappen.HuurderId",
type: "select",
placeholder: "Selecteer een huurder"
}
],
i18n: {
create: {
button: "Nieuw",
title: "Nieuwe invoer",
submit: "Opslaan"
},
edit: {
button: "Bewerken",
title: "Bewerk record",
submit: "Opslaan"
},
remove: {
button: "Verwijder",
title: "Verwijder",
submit: "Verwijder",
confirm: {
_: "Weet u zeker dat u %d records wilt verwijderen?",
1: "Weet u zeker dat u dit record wilt verwijderen?"
}
},
error: {
system: "Er is een systeemfout opgetreden. Neem aub contact op met de ontwikkelaar."
},
datetime: {
previous: 'Vorige',
next: 'Volgende',
months: ['Januari', 'Februari', 'Maart', 'April', 'Mei', 'Juni', 'Juli', 'Augustus', 'September', 'Oktober', 'November', 'December'],
weekdays: ['Zo', 'Ma', 'Di', 'Wo', 'Do', 'Vr', 'Za']
}
}
});
var huurderExtraEigenschappenTable = $('#huurderExtraEigenschappenTable').DataTable({
dom: "Bfrtip",
ajax: {
url: "/Gebouwen/HuurderExtraEigenschappenTable",
type: "POST",
data: function (d) {
var selectedHuurderrow = huurderTable.row({ selectedHuurderrow: true });
if (selectedHuurderrow.any()) {
d.HuurderId = selectedHuurderrow.data().Huurders.id
}
}
},
serverSide: true,
order: [[1, 'asc']],
pageLength: 10,
language: {
url: '/json/datatables-dutch.json'
},
columns: [
{ data: "HuurderExtraEigenschappen.Ingangsdatum" },
{ data: "HuurderEigenschapTypen.Naam" },
{ data: "HuurderExtraEigenschappen.Waarde" },
{ data: "Huurders.NaamHuurder" }
],
select: [{
style: 'single'
}],
buttons: [
{ extend: "create", editor: huurderExtraEigenschappenEditor },
{ extend: "edit", editor: huurderExtraEigenschappenEditor },
{ extend: "remove", editor: huurderExtraEigenschappenEditor }
]
});
huurderExtraEigenschappenTable.buttons().container()
.appendTo($('.col-md-6:eq(0)', huurderExtraEigenschappenTable.table().container()));
huurderTable.on('select', function (e) {
huurderExtraEigenschappenTable.ajax.reload();
huurderExtraEigenschappenEditor
.field('HuurderExtraEigenschappen.HuurderId')
.def(huurderTable.row({ selected: true }).data().id);
});
huurderTable.on('deselect', function () {
huurderExtraEigenschappenTable.ajax.reload();
});
huurderExtraEigenschappenEditor.on('submitSuccess', function () {
huurderTable.ajax.reload();
});
huurderEditor.on('submitSuccess', function () {
huurderExtraEigenschappenTable.ajax.reload();
});
});
This discussion has been closed.
Answers
C#
that isn't going to work -
selectedHuurderrow
is not a selector modifier that DataTables will understand. Try:Also, since you are using server-side processing, instead of:
Use:
If they don't resolve the issue, can you link to the page please.
Thanks,
Allan
Hi,
Thank you so much.
It resolves almost everything. However,
The edit and remove buttons also don't work for the child table. I cannot select a row.
And
Doesn't seem to work. The select menu doesn't have the right option selected when I press new
I don't see anything in the code above that would cause the rows in the child row not to be selectable. Does the
huurderExtraEigenschappenTable
table exist in the document when that code is executed? I'm guessing so, since I don't see anything that is inserting it. If it doesn't though, then you need to call$.fn.DataTable.select.init(huurderExtraEigenschappenTable);
since it needs to be in the document for Select to be automatically initialised.If that doesn't help, I'd need a link to the page showing the issue to be able to help and debug it.
Thanks,
Allan
The row in the child table was not selectable because of the [ ]
should be
That would do it - well spotted.
Allan