jqwidgets,jqxGrid禁止某个单元格不能编辑

If you want to disable the editing of some rows or cells in jqxGrid, you can create a function with two parameters – row’s index and datafield. It this post, we will use only the row’s index.

Here’s the function’s definition:

var beginedit = function(row, datafield) {
if ((row == 1) || (row == 3) || (row == 5)) {
return false;
};
};

Each Grid column has a callback function which is invoked when a cell enters into edit mode. The function’s name is: cellbeginedit. To disable the editing, we will set the cellbeginedit of all grid columns to point to the beginedit function. The resulting behavior will be disabled editing of the second, fourth and sixth rows.

In case you want to disable the editing of a specific cell, you will have to use the column’s datafield, too.

For Example:

var beginedit = function(row, datafield) {
if (row == 1 && datafield == 'firstname') {
return false;
};
};

The above code will disable the editing of the second cell in a column with datafield equal to ‘firstname’.

Online Demo: [url]http://jsfiddle.net/jqwidgets/NFVL5/1/[/url]
// prepare the data
var data = generatedata(10);
var source = {
localdata: data,
datatype: "array",
updaterow: function(rowid, rowdata) {
// synchronize with the server - send update command
}
};
var dataAdapter = new $.jqx.dataAdapter(source);
// initialize jqxGrid
// cancels the editing of desired rows
var beginedit = function(row, datafield, columntype) {
if ((row == 1) || (row == 3) || (row == 5)) {
return false;
};
};

// renders the cells of the non editable rows
var cellsrenderer = function(row, columnfield, value, defaulthtml, columnproperties) {
if ((row == 1) || (row == 3) || (row == 5)) {
var formattedValue = value;
if (columnproperties.cellsformat == "yyyy-MM-dd" || columnproperties.columntype == 'datetimeinput') {
formattedValue = $.jqx.dataFormat.formatdate(formattedValue, columnproperties.cellsformat);
}
else if (columnproperties.cellsformat != "") {
formattedValue = $.jqx.dataFormat.formatnumber(formattedValue, columnproperties.cellsformat);
}
return '<div style="height: 100%; background-color: #BBBBBB;"><span style="float: ' + columnproperties.cellsalign + '; position: relative; margin: 4px;">' + formattedValue + '</span></div>';
};
};

$("#jqxgrid").jqxGrid({
autoheight: true,
source: dataAdapter,
editable: true,
selectionmode: 'singlecell',
columns: [
{
text: 'First Name',
datafield: 'firstname',
width: 90,
cellbeginedit: beginedit,
cellsrenderer: cellsrenderer},
{
text: 'Last Name',
datafield: 'lastname',
width: 90,
cellbeginedit: beginedit,
cellsrenderer: cellsrenderer},
{
text: 'Product',
datafield: 'productname',
width: 177,
cellbeginedit: beginedit,
cellsrenderer: cellsrenderer},
{
text: 'Ship Date',
datafield: 'date',
width: 90,
cellsalign: 'right',
cellsformat: 'yyyy-MM-dd',
cellbeginedit: beginedit,
cellsrenderer: cellsrenderer,
},
{
text: 'Quantity',
datafield: 'quantity',
cellsalign: 'right',
cellbeginedit: beginedit,
cellsrenderer: cellsrenderer,
},
{
text: 'Price',
datafield: 'price',
width: 65,
cellsalign: 'right',
cellsformat: 'c2',
cellbeginedit: beginedit,
cellsrenderer: cellsrenderer}]
});​
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值