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

jpfigueirajpfigueira Posts: 3Questions: 1Answers: 0
edited June 2016 in Free community support

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 }
            ]
        });
    });

Answers

  • jpfigueirajpfigueira Posts: 3Questions: 1Answers: 0

    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.

  • gjwestenenggjwesteneng Posts: 5Questions: 2Answers: 0

    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?

  • jpfigueirajpfigueira Posts: 3Questions: 1Answers: 0
    edited October 2016

    I still haven't found a workaround regarding this issue.

  • allanallan Posts: 63,818Questions: 1Answers: 10,517 Site admin

    Let's track this issue in this thread.

    Allan

This discussion has been closed.