This is a migrated thread and some comments may be shown as answers.

Setting GridCheckBoxColumn using JavaScript

2 Answers 161 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Dan
Top achievements
Rank 2
Dan asked on 10 Apr 2009, 08:12 PM

In our application we have a Radgrid that contains several GridBoundColumns and a few GridCheckBoxColumns. Here is the code that defines 2 of them:

 

<telerik:GridBoundColumn

    UniqueName="gbcWBSNumber"

    DataField="WBSNumber"

    HeaderStyle-HorizontalAlign="Center"

    ItemStyle-HorizontalAlign="Center" 

    HeaderText="WBS #">

</telerik:GridBoundColumn>

 

<telerik:GridCheckBoxColumn

    UniqueName="gccAllowBoes"

    DataField="AllowBoes"

    HeaderStyle-HorizontalAlign="Center"

    ItemStyle-HorizontalAlign="Center" 

    HeaderText="Allow<br />BOEs">

</telerik:GridCheckBoxColumn>  

 

 

 

We need a way to adjust the settings of these two objects using JavaScript. We are doing this successfully for the GridBoundColumn but not for the GridCheckBoxColumn.

                      

In the following (greatly abbreviated) JavaScript we are able to obtain a reference to both objects(stored in the  global variables WBSNumber  and AllowBOEs  respectively):

 

function WBSGridDoubleClick(sender, eventArgs)

{  

    (code removed…)

WBSNumber   =     MasterTableView.getCellByColumnUniqueName(MasterTableView.get_dataItems()[index], "gbcWBSNumber");

 

AllowBOES      = MasterTableView.getCellByColumnUniqueName(MasterTableView.get_dataItems()[index], "gccAllowBOEs");

 

      (code removed…)           

}

 

After some other processing we acquire new values that we need to use to reset these two objects.

 

We have the following JavaScript code in our program to hopefully accomplish this:

 

function OnClientCloseWBSEast(oWnd)

{

    // call a webservice to retrieve the modified data

    WBSData.GetThisWBS(keyValues, OnGetThisWBSComplete);

}

   

// dt is actually an array of strings that contains the

// information we need

function OnGetThisWBSComplete(dt)

{    

        WBSNumber.innerText = dt[0]; // works fine!!!

        AllowBOES.innertext = dt[4] // returns ‘true’ or ‘false’

}

 

Unfortunately, even though the value returned from the webservice in dt[4] reflects the latest change by the user,  the ‘innerText’ property causes the checkbox to be removed and the value ‘true’ or ‘false’ to appear in the cell.

 

We have also tried innerHTML, value, and checked as properties for our CheckBox object but none of these work any better.

 

Can someone tell us what the proper syntax would be?

 

Thanks.

2 Answers, 1 is accepted

Sort by
0
Tsvetoslav
Telerik team
answered on 13 Apr 2009, 02:33 PM
Hi Daniel,

You can access the value of the check box control as follows:

AllowBOES.getElementsByTagName('input').item().checked 

I hope this helps.

Best Regards,
Tsvetoslav
the Telerik team

Check out Telerik Trainer , the state of the art learning tool for Telerik products.
0
Dan
Top achievements
Rank 2
answered on 13 Apr 2009, 03:33 PM
Hi Tsvetoslav:

Yes, thank you, your answer was absolutely correct and my checkboxes are now working!

I did have toi make one minor adjustment to my JavaScript to interrigate the text coming back from my array of strings and set the 'checked' property of the CheckBox object to a boolean true or false... as follows;

        var strAllowBOES    = dt[3];
        if (strAllowBOES == "True")
        {
            AllowBOES.getElementsByTagName('input').item().checked = true;
        }
        else   
        {
            AllowBOES.getElementsByTagName('input').item().checked = false;
        }

with this minor adjustment I got precisely what I was looking for.

Thank You
Tags
Grid
Asked by
Dan
Top achievements
Rank 2
Answers by
Tsvetoslav
Telerik team
Dan
Top achievements
Rank 2
Share this question
or