jsgrid icon indicating copy to clipboard operation
jsgrid copied to clipboard

How to disable specific row when grid have edit mode on?

Open ChetanChaudhari03 opened this issue 8 years ago • 2 comments

Hi,

I have jsGrid. In this gird edit mode is on. But on some of row i don't want to give for edit. So How can i do this in JSGird?

Please help me for that.

Thanks, Chetan Chaudhari

ChetanChaudhari03 avatar Jul 24 '18 12:07 ChetanChaudhari03

Use the editTemplate function when defining the fields. In that function, determine whether the row should be editable or not, and set readonly to true or false accordingly:

	fields: [
		{name: "serviceid", title: "ServiceId", type: "text", visible: false },
		{name: "service", width: 200, title: "Service", type: "text", editing: false },
		{name: "additional_info", width: 300, title: "Additional Info", type: "text", 
        editTemplate: function(value, item) {
                var $result = jsGrid.fields.text.prototype.editTemplate.apply(this, arguments);
                if(item.additionalfield == true)
                {
                    $result.prop("readOnly", false );
                }
                else
                {
                    $result.prop("readonly", true);
                }
                
                return $result;                    
            }
        },
        {name: "additionalfield", width: 10, title: "Info Required", type: "text", visible: false },
		{type: "control" }
	]

Another way to do it is to use the onItemEditing function:

    onItemEditing: function(args) {
        if(args.item.additionalfield == false) {
            args.cancel = true;
        }
    },

This will prevent the field from editing at all, whereas the previous answer will still allow the cell to APPEAR to be editable, but the field will actually be read only.

brichardson2013 avatar Jul 31 '18 15:07 brichardson2013

It works for me, you can try this.

{ type: "control", width: 2, deleteButton: true, editButton: true,
itemTemplate: function(value, item) {
            var $result = $([]);

            if(this.editButton) {
                 //add your condition
                if(item.disableedit != true)
                     $result = $result.add(this._createEditButton(item));
            }

            if(this.deleteButton) {
                $result = $result.add(this._createDeleteButton(item));
            }

            return $result;
        }
}

mofrafrank avatar Jan 17 '23 03:01 mofrafrank