Jquery dataTable Editable Cell

2019-08-04 10:46发布

问题:

I give up as I have been messing around with this for the past 4 hours and I am just not getting anywhere. When using the jquery datatable found here. http://datatables.net/examples/api/editable.html (seems like a very popular plug in) I can get pretty much everything I want to work except the editable cell part. I have my file in this order

<script src="JS/jquery.js"></script>
<script src="JS/jquery.dataTables.min.js" type="text/javascript"></script>
<script src="JS/jquery.jeditable.js"></script>
<script src="JS/jquery.validate.js"></script>
<script src="JS/ColReorder.min.js"></script>
<link href="JS/css/jquery.dataTables.css" rel="stylesheet" />

and then I have this script to get the table initialized.

function formattable(thistable) {
        //alert(thistable + " from format table")
       // $(document).ready(function () {
            //  ADPControlProcessor_Table1
        //$("#ADPControlProcessor_GridView1").dataTable();

        var oTable = $("#ADPControlProcessor_GridView1").dataTable({
                //"bFilter": true,
                "sScrollY": "200px",
                "bPaginate": false,
                "bAutoWidth": false,
                "sDom": 'Rlfrtip'



            //});
            //alert("running");
       });

        //var oTable = $('#example').dataTable();

        /* Apply the jEditable handlers to the table */
        $('td', oTable.fnGetNodes()).editable('../examples_support/editable_ajax.php', {
            "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"
        });

I dont know what elese to try. can anyone point me in the right direction.

回答1:

you are not initialize correct Try this one

$(document).ready(function() {
        /* Init DataTables */
        var oTable = $('#example').dataTable();

        /* Apply the jEditable handlers to the table */
        $('td', oTable.fnGetNodes()).editable( '../examples_support/editable_ajax.php', {
            "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"
        } );
    } );

here is live example click here



回答2:

Instead of paying for the editable plugin I built my own which you're free to use. 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());
}