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

Why my javascript function collapse all radgrid items except one ?

2 Answers 124 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Mehdi
Top achievements
Rank 1
Mehdi asked on 05 Jun 2013, 11:34 AM
Hello everyone.
I am writing about a problem item "expanded and collapsed". I created a button that will "expand" or "collapsed" my items according to their status by calling a simple javascript function .
(If the item is expanded ==> item equal collapse and if the item is collapsed ==> item equal expanded).

Almost everything works perfectly. but I do not know why there is always an item at the top of my grid is always "extended". But when I debug my javascript function, I can see that my loop, foreach well on all items.

Here is my javascript code that allows me to expand or hide items based on their condition.
                function expandCollpaseAllIncident() {
                var Grid = $find("<%= RadGridToolIncident.ClientID %>");
                var MasterTable = Grid.get_masterTableView();
                for (var i = 0; i < MasterTable.get_dataItems().length; i++) {
                    var row = MasterTable.get_dataItems()[i];
                    if (row.get_expanded() == false) {
                        row.set_expanded(true);
                    }
                    else {
                        row.set_expanded(false);
                    }
                }
 
            }

And my RadGrid code Asp:
<telerik:RadGrid ShowHeader="false" ID="RadGridToolIncident" runat="server" DataSourceID="SqlDataSourceAllIncidents"
                                OnItemDataBound="RadGridToolIncident_ItemDataBound" AutoGenerateColumns="false" EnableEmbeddedSkins="false" CssClass="gridIncident_pilotageGeneral">
                                    <MasterTableView runat="server" DataSourceID="SqlDataSourceAllIncidents" DataKeyNames="toolsID"
                                    CssClass="tableBlockPilotageIncident" Width="196px" >
                                    <NoRecordsTemplate>
                                        <asp:Label runat="server" ID="lbNoRecorsTool" Text='<%$ Resources:IRM, tool_action_label_no_current %>'></asp:Label>
                                    </NoRecordsTemplate>
 
                                    <Columns>
                                        <telerik:GridTemplateColumn UniqueName="toolsID" Visible="false">
                                            <ItemTemplate>
                                                <asp:HiddenField runat="server" ID="lbIDTool" Value='<%# Bind("toolsID") %>'  ClientIDMode="Static"/>
                                            </ItemTemplate>
                                        </telerik:GridTemplateColumn>
                                        <telerik:GridTemplateColumn  Visible="false">
                                            <ItemTemplate>
                                                <asp:Label runat="server" ID="lbIDRisk" Text='<%# Bind("riskID") %>' ForeColor="#92c4f7"
                                                    Font-Bold="false" Font-Size="9px" Visible="false"></asp:Label>
                                            </ItemTemplate>
                                        </telerik:GridTemplateColumn>
                                        <telerik:GridTemplateColumn UniqueName="num" ItemStyle-CssClass="cellNumTool">
                                            <ItemTemplate>
                                                <asp:Label runat="server" ID="lbIDnum" Text='<%# Bind("num") %>' CssClass="numGridAction"
                                                    Font-Bold="false" Font-Size="13px" Visible="true"></asp:Label>
                                            </ItemTemplate>
                                        </telerik:GridTemplateColumn>
                                        <telerik:GridTemplateColumn UniqueName="NameIncident" ItemStyle-CssClass="cellNameTool">
                                            <ItemTemplate>
                                                <asp:LinkButton runat="server" ID="linkIncidentDetail" Text='<%# Bind("name") %>' Font-Overline="false"
                                                    CssClass="linkIncident" OnCommand="showToolDetail" Font-Size="14px" CommandName="NameClickIncident"
                                                    CommandArgument='<%# Bind("toolsID") %>' ></asp:LinkButton>
                                            </ItemTemplate>
                                        </telerik:GridTemplateColumn>
                                    </Columns>
                                </MasterTableView>
                            </telerik:RadGrid>

2 Answers, 1 is accepted

Sort by
0
Accepted
Maria Ilieva
Telerik team
answered on 10 Jun 2013, 10:11 AM
Hi Mehdi,

The provided code looks totally correct to me and it is not clear enough what could be the root cause of the problematic behavior you are facing. Could you please elaborate a bit more on when the presented client function is executed and also if there is any server code which executes for covering the needed logic?

Regards,
Maria Ilieva
Telerik
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 the blog feed now.
0
Mehdi
Top achievements
Rank 1
answered on 10 Jun 2013, 02:18 PM
Hi Maria Ilieva,
Thank you very much for your response. You're absolutely right! I tried my javascript function on another Radgrid and everything works perfectly. I noticed that it was due to databind who ironed in the "postback" in the page load.
Tags
Grid
Asked by
Mehdi
Top achievements
Rank 1
Answers by
Maria Ilieva
Telerik team
Mehdi
Top achievements
Rank 1
Share this question
or