0

いくつjqgridかのフィールドがあります。いくつかのセルを

editable:true

また

editable:false

条件に基づく

これが私の関数です(編集済み):

var grid = $("#mygrid");
var getColumnIndexByName = function(gr,columnName) {
var cm = gr.jqGrid('getGridParam','colModel');
for (var i=0,l=cm.length; i<l; i++) {
    if (cm[i].name===columnName) {
        return i; // return the index
    }
}
return -1;
};
function abilitaDisabilitaEditRecord() {
var pos=getColumnIndexByName(grid,'descrizione');
var pos2=getColumnIndexByName(grid,'endDate');
var allIds = $('#mygrid').jqGrid('getDataIDs');
var cells = $("tbody > tr.jqgrow > td:nth-child("+(pos+1)+")",grid[0]);
var cells2 = $("tbody > tr.jqgrow > td:nth-child("+(pos2+1)+")",grid[0]);
for (var i = 0; i < allIds.length; i++) {
    for (var j=0; j<cells.length; j++) {
        var cell = $(cells[j]);
        var cell2 = $(cells2[j]);
    var checkDataFine = $('#mygrid').jqGrid('getCell', allIds[i], 'date');
    if (!checkDataFine==false) {
        cell.addClass('not-editable-cell');
        cell2.addClass('not-editable-cell');
        }   
    }
}
}
4

2 に答える 2

0

実用的な解決策は次のとおりです。

var grid = $("#mygrid");
var getColumnIndexByName = function(gr,columnName) {
var cm = gr.jqGrid('getGridParam','colModel');
for (var i=0,l=cm.length; i<l; i++) {
    if (cm[i].name===columnName) {
        return i;
    }
}
return -1;
};


function changeEditableByContain() {
var pos=getColumnIndexByName(grid,'field1');
var pos2=getColumnIndexByName(grid,'field2');
var pos3=getColumnIndexByName(grid,'field3');
var pos4=getColumnIndexByName(grid,'field4');
var allIds = $('#mygrid').jqGrid('getDataIDs');
var cells = $("tbody > tr.jqgrow > td:nth-child("+(pos+1)+")",grid[0]);
var cells2 = $("tbody > tr.jqgrow > td:nth-child("+(pos2+1)+")",grid[0]);
var cells3 = $("tbody > tr.jqgrow > td:nth-child("+(pos3+1)+")",grid[0]);
var cells4 = $("tbody > tr.jqgrow > td:nth-child("+(pos4+1)+")",grid[0]);
for (var i = 0; i < allIds.length; i++) {
        var cell = $(cells[i]);
        var cell2 = $(cells2[i]);
        var cell3 = $(cells3[i]);
        var cell4 = $(cells4[i]);

    if (condition...) {
        cell.addClass('editable-cell');
        cell2.addClass('editable-cell');
        cell3.addClass('editable-cell');
        cell4.addClass('editable-cell');
        }
    else{
        cell.addClass('not-editable-cell');
        cell2.addClass('not-editable-cell');
        cell3.addClass('not-editable-cell');
        cell4.addClass('not-editable-cell');
    }
}
}

次に、onloadcompleteを呼び出します。

changeEditableByContain();
于 2012-07-27T14:35:23.433 に答える