Earn Cash from forex trading and free 5$ for Regiatation.

Monday, June 1, 2009

How to prevent a cell from being edited on the client in UltraWebGrid in javascript?



Here is a method for implementing the functionality of editing only certain cells when the column's AllowUpdate property is set to false. If you cancel the BeforeEnterEditMode event on the client by returning true, the user will not be able to edit that cell.

First, add a handler for the client-side event BeforeEnterEditMode. This property can be set either in the Property Pages under displaylayout>ClientsideEvents>BeforeEnterEditMode or in code:

UltraWebGrid1.DisplayLayout.ClientSideEvents.BeforeEnterEditModeHandler = "BeforeEdit"

This event receives two parameters, gridname and cellid. You would return true to cancel the event which would stop the cell from being edited. The following script demostrates how to cancel the event for any row whose cell in column one ha a value of true.

function BeforeEdit(gridname, cellid)
{
//get the cell that is about to be edited
var row=igtbl_getRowById(cellid);
//get the value for column 1 in the current row, gets the value by getting the cell's row object then goes into the row's cell array
var value=row.getCell(1).getValue();
//check if the value is true, if so then don't allow editing of the column, cancel event by returning true, else do nothing and allow editing
if(value==true)
{
return true;
}
//or in this case since we are basing the editing on the boolean value you could just say
//return value and omit the if statement.
}

1 comments:

Unknown said...

Hi,Having the perfect contract is a vital part of the web development services. Each web project in Web Design Cochin requires its own web development or web design contract and agreement.Thanks......