Trying to populate a checkbox - One to many join where the link table is empty
Trying to populate a checkbox - One to many join where the link table is empty
jpfigueira
Posts: 3Questions: 1Answers: 0
Hello, like I said in the title, I'm trying to populate a checkbox but it's failing because the link table is empty. If I manually insert 1 record in the database it starts working properly. However, until that first record exists it doesn't show the checkboxes.
DataTables.DtResponse response = new DataTables.Editor(db, "Classes", "Id")
.Field(new DataTables.Field("Classes.Id"))
.Field(new DataTables.Field("Classes.Year"))
.Field(new DataTables.Field("Classes.Class"))
.Field(new DataTables.Field("Classes.SchoolId")
.Options("Schools", "Id", "Name")
)
.Field(new DataTables.Field("Schools.Name"))
.LeftJoin("Schools", "Classes.SchoolId", "=", "Schools.Id")
.MJoin(
new DataTables.MJoin("Subjects")
.Link("Subjects.Id", "ClassesSubjects.SubjectId")
.Link("Classes.Id", "ClassesSubjects.ClassId")
.Field(new DataTables.Field("Id")
.Options("Subjects", "Id", "Name")
)
.Field(new DataTables.Field("Name"))
)
.Process(HttpContext.Current.Request)
.Data();
Response.Write(Json.Encode(response));
var turmasEditor;
$(document).ready(function () {
turmasEditor = new $.fn.dataTable.Editor({
ajax: 'http://notaexemplar.thisfunctional.pt/Scripts/DatatablesEditor/Turmas.cshtml',
table: '#tbTurmas',
fields: [
{ label: 'Year', name: 'Classes.Year' },
{ label: 'Class', name: 'Classes.Class' },
{ label: 'School', name: 'Classes.SchoolId', type: "select" },
{ label: 'Subjects', name: 'Subjects[].Id', type: "checkbox" },
// etc
],
});
$('#tbTurmas').DataTable({
ajax: 'http://notaexemplar.thisfunctional.pt/Scripts/DatatablesEditor/Turmas.cshtml',
dom: 'Bfrtip',
bProcessing: true,
columns: [
{ data: 'Classes.Year' },
{ data: 'Classes.Class' },
{ data: 'Schools.Name' },
{ data: 'Subjects', render: "[, ].Name" },
// etc
],
select: true,
buttons: [
{ extend: 'create', editor: turmasEditor },
{ extend: 'edit', editor: turmasEditor },
//{ extend: 'remove', editor: editor }
]
});
});
This discussion has been closed.
Answers
Here is an example.
http://live.datatables.net/beluyivu/1/edit
By removing the subjects from the class, the checkboxes disappear until they're manually inserted on the database.
I experience the same issue. The issue can also be reproduced in the example project/database that comes with the package. You can assign access to users in the datatables example (JoinArrayController), but when the link table is empty the checkbox dropdown won't populate.
Is there a workaround?
I still haven't found a workaround regarding this issue.
Let's track this issue in this thread.
Allan