Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
180
How to disable a webdatagrid's cell dynamically
posted

Hi,

I would like to know how can I disable a WebDataGrid's cell dynamically. Let's say you have two columns, first is a checkbox and second is a text. So how can I disable editing of second column when the checkbox is unchecked and re-enable editing when checkbox is checked by the user? How to do it in javascript and code-behind?

 

Thank you,

Pascal

Parents
  • 14049
    Verified Answer
    Offline posted

    Hello Pascal,

    Assuming you are using templates for the check box column and the checkbox is the only control in that template, something like the following can be used for your scenario.

    Handle the EnteringEditMode event off of the CellEditing behavior.

    <ig:EditingCore>

          <Behaviors>

                <ig:CellEditing>

                      <CellEditingClientEvents EnteringEditMode="enteringEditMode" />

                </ig:CellEditing>

          </Behaviors>

    </ig:EditingCore>

     

    The event handler may look like this:

    function enteringEditMode(grid, eventArgs)

    {

          var cell = eventArgs.getCell();

     

          if (cell.get_column().get_key() == "SecondColumn")

          {

                checkboxCell = cell.get_row().get_cellByColumnKey("FirstColumn");

                if (!checkboxCell.get_element().firstChild.checked)

                      eventArgs.set_cancel(true);

          }

    }

     

Reply Children
No Data