Check / Uncheck ClientSelectColumn from client side

3 posts, 0 answers
  1. Lokesh
    Lokesh avatar
    89 posts
    Member since:
    Jul 2012

    Posted 25 Oct 2011 Link to this post

    Hi Team,
    I have a aradgrid with some bound columns, CheckBox column and ClientSelect Column
    What I want is, when I select All Rows (by clicking select all), i dont want some of the rows to get selected based on the values in my CheckBox column.
    And I want this functionality from client side.
    I tried this with server side DataBound Event and it worked (though not completly.)

    here is my aspx :
    <telerik:RadGrid ID="rgProjectBudget" runat="server" AllowFilteringByColumn="true" AllowMultiRowSelection="true" AllowPaging="true"
                                                OnNeedDataSource="rgProjectBudget_NeedDataSource" OnDeleteCommand="rgProjectBudget_DeleteCommand" PageSize="50"
                                                OnItemDataBound="rgProjectBudget_ItemDataBound" OnPreRender="rgProjectBudget_PreRender" PagerStyle-AlwaysVisible="true" >
                                                <ClientSettings  Selecting-AllowRowSelect="true">
                                                    <ClientEvents OnRowSelected="RowSelected" />
                                                </ClientSettings>
                                        <MasterTableView EditMode="InPlace">
                                        <Columns>
                                            <telerik:GridBoundColumn DataField="COABudgetDetailID" DataType="System.Int32"
                                                                    HeaderText="COABudgetDetailID" Display="false"
                                                                    UniqueName="COABudgetDetailID" AutoPostBackOnFilter="true">
                                            </telerik:GridBoundColumn>
                                            <telerik:GridBoundColumn DataField="EntityKeyName" DataType="System.String" FilterControlWidth="40%"
                                                                    HeaderText="Project Name" AllowFiltering="true" AutoPostBackOnFilter="true"
                                                                    CurrentFilterFunction="Contains" UniqueName="EntityKeyName">
                                                <HeaderStyle Width="32%" HorizontalAlign="Left" />
                                                <ItemStyle  Width="32%" HorizontalAlign="Left" />
                                            </telerik:GridBoundColumn>
                                            <telerik:GridBoundColumn DataField="ChartOfAccountSetDetailValueCode" DataType="System.String"
                                                                    HeaderText="Project Heads" AllowFiltering="true" AutoPostBackOnFilter="true" FilterControlWidth="30%"
                                                                    CurrentFilterFunction="Contains" UniqueName="ChartOfAccountSetDetailValueCode">
                                                 <HeaderStyle Width="10%" HorizontalAlign="Left" />
                                                <ItemStyle  Width="10%" HorizontalAlign="Left" />
                                            </telerik:GridBoundColumn>
                                            <telerik:GridBoundColumn DataField="ChartOfAccountSetDetailDescription" DataType="System.String"
                                                                     HeaderText="Description" AllowFiltering="true" AutoPostBackOnFilter="true"
                                                                     CurrentFilterFunction="Contains" UniqueName="ChartOfAccountSetDetailDescription"
                                                                     FilterControlWidth="60%">
                                                <HeaderStyle Width="20%" HorizontalAlign="Left" />
                                                <ItemStyle  Width="20%" HorizontalAlign="Left" />
                                            </telerik:GridBoundColumn>
                                            <telerik:GridBoundColumn UniqueName="QuotedValue" HeaderText="Quoted Amount" DataField="QuotedValue"
                                                                     CurrentFilterFunction="EqualTo" AllowFiltering="true" DataType="System.Double" FilterControlWidth="30%"
                                                                     AutoPostBackOnFilter="true">
                                                <HeaderStyle Width="10%" HorizontalAlign="Left" />
                                                <ItemStyle  Width="10%" HorizontalAlign="Left" />
                                            </telerik:GridBoundColumn>
                                             <telerik:GridTemplateColumn HeaderText="Project Budget" UniqueName="SecondaryEntityBudget" DataField="SecondaryEntityBudget"
                                                                        CurrentFilterFunction="Contains" AllowFiltering="true" AutoPostBackOnFilter="true">
                                                                        <ItemStyle Width="10%" />
                                                <ItemTemplate>
                                                   <asp:TextBox ID="txtBudgetAmount" runat="server" Width="70px"
                                                            Text='<%# DataBinder.Eval(Container,"DataItem.SecondaryEntityBudget") %>' />
                                                </ItemTemplate>
                                                 <HeaderStyle Width="10%" HorizontalAlign="Left" />
                                                <ItemStyle  Width="10%" HorizontalAlign="Left" />
                                            </telerik:GridTemplateColumn>
                                            <telerik:GridBoundColumn UniqueName="COAActualAmount" HeaderText="Actual Amount" DataField="COAActualAmount"
                                                                     CurrentFilterFunction="EqualTo" AllowFiltering="true" DataType="System.Double" FilterControlWidth="30%"
                                                                     AutoPostBackOnFilter="true">
                                                <HeaderStyle Width="10%" HorizontalAlign="Left" />
                                                <ItemStyle  Width="10%" HorizontalAlign="Left" />
                                            </telerik:GridBoundColumn>
                                            <telerik:GridTemplateColumn HeaderText="Supplementary Budget1" UniqueName="SupplementaryBudget1" Display="true" DataField="SupplementaryBudget1"
                                                                        CurrentFilterFunction="Contains" AllowFiltering="true" AutoPostBackOnFilter="true">
                                                                        <ItemStyle Width="20%" />
                                                <ItemTemplate>
                                                   <asp:TextBox ID="txtSupplementaryBudget1" runat="server" Width="70px" Enabled="false"
                                                            Text='<%# DataBinder.Eval(Container,"DataItem.SupplementaryBudget1") %>' />
                                                </ItemTemplate>
                                            </telerik:GridTemplateColumn>
                                            <telerik:GridTemplateColumn HeaderText="Supplementary Budget2" UniqueName="SupplementaryBudget2" Display="true" DataField="SupplementaryBudget2"
                                                                        CurrentFilterFunction="Contains" AllowFiltering="true" AutoPostBackOnFilter="true">
                                                <ItemStyle Width="20%" />
                                                <ItemTemplate>
                                                   <asp:TextBox ID="txtSupplementaryBudget2" runat="server" Width="70px" Enabled="false"
                                                            Text='<%# DataBinder.Eval(Container,"DataItem.SupplementaryBudget2") %>' />
                                                </ItemTemplate>
                                            </telerik:GridTemplateColumn>
                                            <telerik:GridBoundColumn DataField="StatusID" DataType="System.Int32"
                                                                     HeaderText="StatusID" UniqueName="StatusID"
                                                                     Display="false">
                                            </telerik:GridBoundColumn>
                                            <telerik:GridHyperLinkColumn DataTextField="StatusName" DataType="System.String" ItemStyle-HorizontalAlign="Center"
                                                                     HeaderText="Status" UniqueName="StatusName" CurrentFilterFunction="Contains" AutoPostBackOnFilter="true"
                                                                     DataNavigateUrlFields="COABudgetDetailID,SecondaryEntityBudget,SupplementaryBudget1,SupplementaryBudget2"
                                                                     DataNavigateUrlFormatString="javascript:CheckBudgetAmount({0},{1},{2},{3});" >
                                            </telerik:GridHyperLinkColumn>
                                            <telerik:GridBoundColumn DataField="SecondaryEntityBudgetApproved" DataType="System.Double" Display="false"
                                                                     HeaderText="SecondaryEntityBudgetApproved" UniqueName="SecondaryEntityBudgetApproved">
                                            </telerik:GridBoundColumn>
                                            <telerik:GridBoundColumn DataField="SupplementaryBudget1Approved" DataType="System.Double" Display="false"
                                                                     HeaderText="SupplementaryBudget1Approved" UniqueName="SupplementaryBudget1Approved">
                                            </telerik:GridBoundColumn>
                                            <telerik:GridBoundColumn DataField="SupplementaryBudget2Approved" DataType="System.Double" Display="false"
                                                                     HeaderText="SupplementaryBudget2Approved" UniqueName="SupplementaryBudget2Approved">
                                            </telerik:GridBoundColumn>
                                            <%--<telerik:GridBoundColumn DataField="StatusName" DataType="System.String"
                                                                     HeaderText="Status" UniqueName="Status">
                                            </telerik:GridBoundColumn>--%>
                                              
                                            <telerik:GridTemplateColumn HeaderText="Not Applicable" UniqueName="IsBudgetNotApplicable" FilterControlWidth="20%"
                                                                        CurrentFilterFunction="Contains" AllowFiltering="true" AutoPostBackOnFilter="true" Display="false">
                                                <ItemTemplate>
                                                    <asp:CheckBox ID="chkApplicable" runat="server" Checked='<%# DataBinder.Eval(Container,"DataItem.IsBudgetNotApplicable") %>' />
                                                </ItemTemplate>
                                                <ItemStyle HorizontalAlign="Left" Width="5%"/>
                                                <HeaderStyle  Width="5%" />
                                            </telerik:GridTemplateColumn>
                                              
                                            <telerik:GridCheckBoxColumn DataField="IsParent" UniqueName="IsParent" HeaderText="IsParent" Visible="true">
                                            </telerik:GridCheckBoxColumn>
                                              
                                            <telerik:GridClientSelectColumn HeaderText="Select" UniqueName="Select">
                                            </telerik:GridClientSelectColumn>
                                            <telerik:GridButtonColumn CommandName="Delete" HeaderText="Delete?"
                                                Text="Delete" UniqueName="DeleteCommandColumn" ButtonType="ImageButton" 
                                                            ConfirmText="Are you sure you want to delete ?">
                                                <ItemStyle HorizontalAlign="Left" Width="5%"/>
                                                <HeaderStyle Width="5%" />
                                            </telerik:GridButtonColumn>
                                        </Columns>
                                    </MasterTableView>
                               </telerik:RadGrid>


    And I have reached upto this :

     

    function RowSelected(sender, eventArgs)

     

    {

     

    var grid = sender;

     

     

    var MasterTable = grid.get_masterTableView();

     

     

    var row = MasterTable.get_dataItems()[eventArgs.get_itemIndexHierarchical()];

     

     

    var cell = MasterTable.getCellByColumnUniqueName(row, "IsParent");

     

     

    //here cell.innerHTML holds the value of the cell

     

    alert(cell.innerHTML);

     

    // cell.innerHTML doe not return value of CheckBox Column

     

     

    // but returns value if its a bound column

     

    }

    Waiting for your reply.

    Regards,
    Lok..

  2. Lokesh
    Lokesh avatar
    89 posts
    Member since:
    Jul 2012

    Posted 25 Oct 2011 Link to this post

    Hi Team,
    I tried with RowSelecting event from client side

    function RowSelecting(sender, eventArgs)
     {
            var grid = sender;
            var MasterTable = grid.get_masterTableView();
            var row = MasterTable.get_dataItems()[eventArgs.get_itemIndexHierarchical()];
      
            var cell = MasterTable.getCellByColumnUniqueName(row, "IsParent1");
            var col = MasterTable.getCellByColumnUniqueName(row, "Select");
      
            if (cell.innerHTML == "True") {
            eventArgs.set_cancel(true);
            }
    }

    Now if I Select All Rows (by clicking Header checkbox of ClientSelectColumn), I am able to get what I wanted.. (select only those rows having db field IsParent  == False). (Please see the image)

    But now I got anaother problem...
    I cannot disselect all rows by clicking header checkbox of ClientSelectColumn.

    Could you please help me out with this ???

    Regards,
    Lok..
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Vasil
    Admin
    Vasil avatar
    1547 posts

    Posted 28 Oct 2011 Link to this post

    Hi Lok..,

    The "select all" checkbox will deselect the chekcboxes in the column only if all are currently selected.
    For example if there are 10 selected out of 15 chekcboxes, and you click it, it will select all the 15. Then if you click it again it will deselects all. In your case there are nonselected checkboxes and this is the reason that you can't deselect all by clicking the header checkbox.

    Best wishes,
    Vasil
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now
Back to Top