Inline edit always posting boolean / bit field

Inline edit always posting boolean / bit field

msand01msand01 Posts: 54Questions: 24Answers: 1
edited April 2018 in Editor

During an inline edit of a cell, one of the editable columns in my table (IsActive) - a boolean - always posts back along with the current cell being edited, e.g.:

"action" : "edit",
    "data" : {
        "69730" : {
            "Unit" : "7",
            "IsActive" : "false"
        }
    }

Is there an option or setting I can use to prevent the IsActive column from posting each time, except when it itself is being edited?
This example, https://editor.datatables.net/examples/api/checkbox.html, offers an indirect solution, but I was wondering if there were a simpler way. I am not using a checkbox.

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 61,715Questions: 1Answers: 10,105 Site admin

    I suspect that is happening here is that a string value is being compared to a boolean, so Editor is always finding that there is a change in value.

    If you can give me a link to the page showing the issue I can check that.

    Allan

  • bradmacgregorbradmacgregor Posts: 9Questions: 0Answers: 0

    I am having this issue as well. I would rather use booleans than the strings 'false' and 'true' for the data sent to the browser, but somewhere along the line, the data is being cast as a string.

    editor.ajax = {
                    edit: {
                        type: 'PUT',
                        url: '/api/encodingService',
                        data: function (data) {
                            console.log(data); // sending boolean value as a string regardless of which column is modified.
                            return JSON.stringify(data.data);
                        },
                        "contentType": "application/json"
                    }
    }
    

    I'm using Editor 1.7.0

  • bradmacgregorbradmacgregor Posts: 9Questions: 0Answers: 0
    edited June 2018

    The same happens with null values. they are cast to empty string, and the editor decides it was changed from null to empty string and sends that field along with the request.

    I see that you fixed the null situation in 1.7.3:

    If a null value was given to the form and not modified, Editor would incorrectly determine that the field's value was changed.
    

    Did that address booleans as well?

  • allanallan Posts: 61,715Questions: 1Answers: 10,105 Site admin

    No - that was specific to null values that fix.

    Are your boolean values actually boolean when they are read from the server (i.e. they are boolean in the JSON), or are they strings there?

    Do you have a link to the page you are working on so I can check it out?

    Thanks,
    Allan

  • bradmacgregorbradmacgregor Posts: 9Questions: 0Answers: 0

    The json returned to the client from the server on page load has the boolean value unquoted {'property':false}, not {'property':'false'}, but when any request is sent back to the server, it contains that field as a string. I'll try to get you a working example, but don't have one handy as it is an internal application.

  • bradmacgregorbradmacgregor Posts: 9Questions: 0Answers: 0

    update: I've gotten around this issue by adding the field to the editor like this:

    var fields = editor.fields;
    fields.push({
        type: 'select',
        label: 'Used By LRP',
        name: 'used_by_lrp',
        options: [
            {label: 'No', value: false},
            {label: 'Yes', value: true}
        ]
    });
    

    and rendering the datatable

    config.columnDefs.push(
        {
            'targets': [
                columnIndexes['used_by_lrp']
            ],
            'render': function(data, type, row) {
                return row.used_by_lrp === true ? 'Yes' : 'No';
            }
        }
    );
    

    so now, before it calculates the difference between the original value and the new value, it converts the dropdown to the actual boolean value.

  • allanallan Posts: 61,715Questions: 1Answers: 10,105 Site admin
    Answer ✓

    Thanks - that looks like a good workaround. I'll try to construct something locally with booleans to check it.

    Allan

  • msand01msand01 Posts: 54Questions: 24Answers: 1

    I upgraded to Editor 1.7.4 and Datatables 1.10.18 and this seemed to clear up the issue. Thank you!

This discussion has been closed.