简体   繁体   中英

Using custom fields in jQuery editable DataTable while editing a checkbox

i have a table (generated in asp.net) displayed with the great DataTable jQuery plugin. My table have some editable fields (i used jQuery Datatables editable ) and i already have some custom fields in some of my tables.

This is a table with only 3° column editable that sends two extra parameters (column 3 and 1 of my table): "cell" and "trustedid". This works perfectly:

$('#ctl00_MainContent_tradGrid').dataTable({
    bJQueryUI: true,
    "sPaginationType": "full_numbers",
    "bSortClasses": false
    }).makeEditable({
        sUpdateURL: "/updateData.aspx<% Response.Write(parameters); %>",
        fnOnEditing: function (input) {
            cell = input.parents("tr")
                    .children("td:nth-child(3)")
                    .text();
            trustedid = input.parents("tr")
                    .children("td:nth-child(1)")
                    .text();
            return true
        },
        oUpdateParameters: {
            cell: function () { return cell; },
            trustedid: function () { return trustedid; }
        },
        oEditableSettings: { event: 'click' }
    });

i also have another table with checkboxes on last editable column, and works fine too, this is the code:

$('#ctl00_MainContent_tradGrid').dataTable({
    bJQueryUI: true,
    "sPaginationType": "full_numbers",
    "bSortClasses": false
}).makeEditable({
    sUpdateURL: "/updateChecked.aspx",
    aoColumns: [
        {}, {}, {}, {
            type: 'checkbox',
            submit: 'Ok',
            cancel: 'Cancel',
            checkbox: { trueValue: 'Yes', falseValue: 'No' }
        }
    ]
});

now i need to use a single custom parameter in this second example, but can't do it! This is my try:

$('#ctl00_MainContent_tradGrid').dataTable({
    bJQueryUI: true,
    "sPaginationType": "full_numbers",
    "bSortClasses": false
}).makeEditable({
    sUpdateURL: "/updateChecked.aspx",
    fnOnEditing: function (input) {
        trustedid = input.parents("tr")
                .children("td:nth-child(1)")
                .text();
        return true
    },
    oUpdateParameters: {
        trustedid: function () { return trustedid; }
    },
    aoColumns: [
        {}, {}, {}, {
            type: 'checkbox',
            submit: 'Ok',
            cancel: 'Cancel',
            checkbox: { trueValue: 'Yes', falseValue: 'No' }
        }
    ]
});

but it get the error: Uncaught ReferenceError: trustedid is not defined

How can i do this?

fnOnEditing gets called only on text, select and textarea: if(settings.type == "text" || settings.type == "select" || settings.type == "textarea") around line 209 in jquery.dataTables.editable.js. I used it with some autocomplete fields and it worked. You can add checkbox in that list, but probably you you need some other changes in there as well, since .val() on checkbox would not return the proper value.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM