jQuery DataTable Inline Editing
Asked Answered
P

1

5

I have been trying to implement simple Inline editing in jQuery Datatable. But I cannot activate the edit that happens on click on a row cell. I used the same code as in their site Link:

<table id="Datatable" cellpadding="0" cellspacing="0" border="0" class="display">
    <thead>
        <tr>
            <th>Age</th>
            <th>Name</th>
        </tr>
    </thead>
</table>

Datatable Binding:

    /* Init DataTables */
    var oTable = $('#Datatable').dataTable({
        "bProcessing": true,
        "sAjaxSource":"http://localhost:6220/DataSources/WCF/Data.svc/GetCustomer",
        "aoColumns": [
                            { "mDataProp": "Age" },
                            { "mDataProp": "Name" }
                     ]
    });

/* Apply the jEditable handlers to the table */              oTable.$('td').editable('http://localhost:6220/DataSources/WCF/Data.svc/SaveCustomer', {
                    tooltip: 'Click to edit...',
                    "callback": function (sValue, y) {
                        var aPos = oTable.fnGetPosition(this);
                        oTable.fnUpdate(sValue, aPos[0], aPos[1]);
                    },
                    "submitdata": function (value, settings) {
                        return {
                            "row_id": this.parentNode.getAttribute('id'),
                            "column": oTable.fnGetPosition(this)[2]
                        };
                    },
                "height": "14px",
                "width": "100%"
            });

Any suggestions are highly appreciated.

Presumptive answered 29/4, 2013 at 13:39 Comment(0)
F
20

I built a plugin that'll do this for you in about two lines of code. It's small and pretty basic but gets the job done. The repo is here: DataTables CellEdit Plugin

The basic initialization is quick and easy:

oTable.MakeCellsEditable({
    "onUpdate": myCallbackFunction
});

myCallbackFunction = function (updatedCell, updatedRow) {
    console.log("The new value for the cell is: " + updatedCell.data());
}

Update: This has slowly been growing over the past few months and has quite a few more features than when I first posted this answer. Thanks to all the contributors out there pitching in!

Falkner answered 28/3, 2016 at 16:15 Comment(4)
your plugin is good, but it's not abstract enough, there's too little that can be configured.Kristakristal
Thank you, I'm always happy to take feature requests on the github page (or better yet pull request! :-) )Falkner
Looks great but I need the ability to add new records as wellMcgovern
Love the plugin - but yes, definitely would love to see add new row/delete row options in the settings as wellKosse

© 2022 - 2024 — McMap. All rights reserved.