동적 선택 데이터grid 편집 가능한 열

2606 단어
수요: 새로 추가된 것을 눌렀을 때testOne과testTwo열은 모두 편집할 수 있으며, 수정할 때testTwo만 수정할 수 있습니다
var operates = {
	getRowIndex: function (target) {
		var tr = $(target).closest('tr.datagrid-row');
		return parseInt(tr.attr('datagrid-row-index'));
	},
	addRow:function (index) {
		// testOne 
		var $testOne = $(tableId).datagrid('getColumnOption', 'testOne');
		$testOne = {type:'text'};
		$(tableId).datagrid('insertRow', {
			index: index,
			row: {
			}
		});
		$(tableId).datagrid('selectRow', index);
		$(tableId).datagrid('beginEdit', index);
	}
	cancelRow:function (target) {
		$(tableId).datagrid('cancelEdit', operates.getRowIndex(target));
	},
	editRow: function (target) {
		// testOne 
		var $testOne = $(tableId).datagrid('getColumnOption', 'testOne');
		$testOne = {};
		$(tableId).datagrid('beginEdit', operates.getRowIndex(target));
	},
	saveRow: function (target) {
		$(tableId).datagrid('endEdit', operates.getRowIndex(target));
	}
}

function loadDruginfoPresList(tableId){
	$(tableId).datagrid({
		...
		columns:[[
			{field:'testOne',title:'testOne',width:50,align:'center',editor:{type:'text'}},
			{field:'testTwo',title:'testTwo',width:120,align:'center',editor:{type:'text'}},
			{field: 'operate', title: 'operate', width: 100, align: 'center',
				formatter:function(value,row,index){
					var str="";
					if (row.editing) {
						str += "보존";
						str += "취소 ";
					} else {
						str += "수정하다 ";
						str += "삭제 ";
					}
					return str;
				}
			}
		]],
		onLoadSuccess: function(data){
        },
		onBeforeEdit:function (index,row) {
            row.editing=true;
            $(tableId).datagrid('refreshRow',index);
        },
		onAfterEdit:function (index,row) {
            row.editing=false;
            $(tableId).datagrid('refreshRow',index);
        },
		onCancelEdit:function (index,row) {
            row.editing=false;
            $(tableId).datagrid('refreshRow',index);
        }
	});
}

좋은 웹페이지 즐겨찾기