Unable to return a checkbox value to server ,,

Unable to return a checkbox value to server ,,

rob morningrob morning Posts: 30Questions: 7Answers: 1

I'm playing with Editor and using my own client / server implementation .. I'm using bootstrap (jic !) .. My script is shown below ..

 var editor = new $.fn.dataTable.Editor({
        ajax: {
            "url": "${createLink(action: 'despatchEntryEdit', controller: 'despatchDiary')}",
            type: "POST"
        },
        table: "#despatchEntryDetails",
        "fields": [{
            name: "date"
        }, {
            name: "offset"
        }, {
            name: "despatchTime"
        }, {
            name: "eod",
            type: "checkbox",
            separator: "|"
        }
        ]
    });

    $('#despatchEntryDetails').on('change', 'input.editor-active', function () {
        editor.edit($(this).closest('tr'), false)
                .set('eod', $(this).prop('checked') ? 1 : 0)
                .set('offset',999)
                .submit();
    }).dataTable({
        columns: [
            {data: "date"},
            {data: "offset"},
            {data: "despatchTime"},
            {
                data: "eod",
                render: function (data, type, row) {
                    if(type === 'display'){
                        console.log(data);
                        console.log(type);
                        return '<input type="checkbox" class="editor-active">';
                    }
                    return data;
                },
                className: "dt-body-center"
            }
        ],
        rowCallback: function (row, data) {
            // Set the checked state of the checkbox in the table
            console.log("data.eod" + data.eod);
            $('input.editor-active', row).prop('checked', data.eod == 1);
        }
        ,
        "scrollY": "200px",
        "scrollCollapse": true,
        "paging": false,
        "searching": false,
        "ordering": false,
        "info": false,

        "ajax": {
            "url": "${createLink(action: 'despatchEntryJsonList', controller: 'despatchDiary', params:[id: despatchDiaryInstance?.id])}"
        }

    }).addClass('table order-column table-striped table-bordered table-compressed');

Info comes from my server and the datatable is correctly displayed (with checkbox ('eod') correctly populated). When i click the checkbox the ajax call correctly passes back the 'offset' field with the correct value (999) but the 'eod' field is returned empty. This is very similar to example with the permanent checkbox but i can't see what i'm doing wrong .. The backend is a grails application and this is what gets passed thru ..

[id:1, data[eod]:, action:despatchEntryEdit, data[offset]:999, data[despatchTime]:00:23, data[date]:01-07-2015, format:null, controller:despatchDiary]

with the eod field being empty (incorrectly) and the offset field having the correct value (999) ..

I'm missing something , any help would be appreciated ..

Answers

  • rob morningrob morning Posts: 30Questions: 7Answers: 1

    Solved !! .. but i'd like to understand why so please chip in ..

    Amended the editor.fields.eod .. to read ..

      name: "eod",
                type: "checkbox",
                separator: "|",
                options: [
                    {label: '', value: 1}
                ]
    

    I'm not certain why ...

This discussion has been closed.