Search code examples
datatablesjeditable

condition editing using .editable(..) datatables


Im new to datatables, and Im having this issue thats bugging me for a while. for example, I'm trying to edit the 5th column, but I want to disable it for part of the rows.. is it possible? cause I don't seem to find the way..

                        $('td:eq('5')', oTable.fnGetNodes()).editable('/'+appName+'/GetGenWidgetTableDataServlet', 
                            {
                              type : 'text',
                              tooltip: 'Click to Edit',
                              indicator: 'Saving...',
                              placeholder : '',

                        "callback": function( sValue, y ) {
                            var aPos = oTable.fnGetPosition( this );
                            oTable.fnUpdate( sValue, aPos[0], aPos[2],true,true );
                        },
                        "submitdata": function ( value, settings ) {
                        debugger
                        var iPos = oTable.fnGetPosition( this );
                        var colPos = iPos[2];
                        iPos = iPos[0];
                        if(iPos!=null)
                        {
                            var aData = oTable.fnGetData( iPos );
                            var vRowType = aData[0];
                            var iId = aData[2];
                            var moduleID = iId.split("$")[0];
                            var unitID = iId.split("$")[1];
                            var processID = iId.split("$")[2];
                            var riskID = iId.split("$")[3];
                            var controlID = iId.split("$")[4];
                        }
                            return {
                                "Token": idhref,
                                "moduleID" :moduleID,
                                "unitID": unitID,
                                "processID" :processID ,
                                "riskID": riskID,
                                "controlID": controlID,
                                "rowType":vRowType,
                                "Action": "saveRow",
                                "columnName": aoCols[colPos]["Id"]
                            };
                        },
                        "height": "25px",
                        "width": "50px"
                    }

Solution

  • We use the datatables editable plugin (https://code.google.com/p/jquery-datatables-editable/ ) and it allows you to set a sReadOnlyCellClass. We set that class in the datatable fnRowCallBack function based on the values in the row.

    You could set an "editable" class in your fnRowCallBack

    oTable = $('#resultTable').dataTable( {
        ...
    "fnRowCallback": function( nRow, aData, iDisplayIndex ) {
            if ( aData["something"] == "This row should be editable" )
            {
                nRow.className = "editable";
            }
        return nRow;
        }
        ...
    });
    

    and modify your selector to

    oTable.$('tr.editable td:eq(5)').editable( ...)