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

how reach childs of a row in hierachical rad grid in client side?

1 Answer 45 Views
Grid
This is a migrated thread and some comments may be shown as answers.
samaneh
Top achievements
Rank 1
samaneh asked on 12 Jun 2012, 05:59 AM
hi all

I have a hierachical rad grid in my page
this grid has up to 3 level and each row has a template field that contains rad numeric text box for "grade" and 1 column for "max grade"

user must enter grade for each child in last level. then in client side, I must check that grade:
1)this grade can't upper than max_grade
2)sum of grade of childes must be calculate for grade of their parent

this is my grid:
<telerik:RadGrid ID="gv_cheque_list" runat="server" GridLines="None" Width="100%"
                    AllowSorting="True" AutoGenerateColumns="False" ShowFooter="True" OnDetailTableDataBind="gv_cheque_list_DetailTableDataBind"
                    OnItemCommand="gv_cheque_list_ItemCommand" Skin="Web20" OnItemDataBound="gv_cheque_list_ItemDataBound">
                    <AlternatingItemStyle BackColor="#a7bcdb" />
                    <MasterTableView AllowSorting="True" DataKeyNames="assessment_parameter_id" Dir="RTL"
                        Font-Names="Tahoma" HeaderStyle-HorizontalAlign="Center" HorizontalAlign="Center"
                        HierarchyLoadMode="Client" ItemStyle-HorizontalAlign="Center" HeaderStyle-BackColor="#99CCFF" >
                        <AlternatingItemStyle BackColor="#a7bcdb" />
                        <DetailTables>
                            <telerik:GridTableView runat="server" Name="ChequeList" DataKeyNames="assessment_parameter_id"
                                Font-Names="Tahoma" HierarchyLoadMode="Client" Dir="RTL" NoDetailRecordsText="it hasn't child" >
                                <ParentTableRelation>
                                    <telerik:GridRelationFields DetailKeyField="parent_id" MasterKeyField="assessment_parameter_id" />
                                </ParentTableRelation>
                                <AlternatingItemStyle BackColor="#a7bcdb" />
                                <HeaderStyle HorizontalAlign="Center" CssClass="detailTableLevel1" />
                                <ExpandCollapseColumn>
                                </ExpandCollapseColumn>
                                <Columns>
                                    <telerik:GridTemplateColumn HeaderText="cheque_list_id" UniqueName="cheque_list_id"
                                        Visible="false">
                                        <ItemTemplate>
                                            <asp:Label ID="lbl_cheque_list_id" runat="server" Text='<%# Bind("cheque_list_id") %>' />
                                        </ItemTemplate>
                                        <HeaderStyle Width="50px" />
                                        <ItemStyle Width="50px" />
                                    </telerik:GridTemplateColumn>
                                    <telerik:GridTemplateColumn HeaderText="assessment_parameter_id" UniqueName="assessment_parameter_id"
                                        Visible="false">
                                        <ItemTemplate>
                                            <asp:Label ID="lbl_assessment_parameter_id" runat="server" Text='<%# Bind("assessment_parameter_id") %>' />
                                        </ItemTemplate>
                                        <HeaderStyle Width="50px" />
                                        <ItemStyle Width="50px" />
                                    </telerik:GridTemplateColumn>
                                    <telerik:GridTemplateColumn HeaderText="parent_id" UniqueName="parent_id" Visible="false">
                                        <ItemTemplate>
                                            <asp:Label ID="lbl_parent_id" runat="server" Text='<%# Bind("parent_id") %>' />
                                        </ItemTemplate>
                                        <HeaderStyle Width="50px" />
                                        <ItemStyle Width="50px" />
                                    </telerik:GridTemplateColumn>
                                    <telerik:GridTemplateColumn HeaderText="child_count" UniqueName="child_count" Visible="false">
                                        <ItemTemplate>
                                            <asp:Label ID="lbl_child_count" runat="server" Text='<%# Bind("child_count") %>' />
                                        </ItemTemplate>
                                    </telerik:GridTemplateColumn>
                                    <telerik:GridTemplateColumn HeaderText="type" UniqueName="type" Visible="false">
                                        <ItemTemplate>
                                            <asp:Label ID="lbl_type" runat="server" Text='<%# Bind("type") %>' />
                                        </ItemTemplate>
                                    </telerik:GridTemplateColumn>
                                    <telerik:GridBoundColumn DataField="assessment_parameter_code" EmptyDataText="----"
                                        HeaderText="assessment_parameter_code" Resizable="true" UniqueName="assessment_parameter_code">
                                    </telerik:GridBoundColumn>
                                    <telerik:GridBoundColumn DataField="parameter_name" EmptyDataText="----" HeaderText="parameter_name"
                                        Resizable="true" UniqueName="parameter_name">
                                    </telerik:GridBoundColumn>
                                    <telerik:GridBoundColumn DataField="max_grade" EmptyDataText="----" HeaderText="max_grade"
                                        Resizable="true" UniqueName="max_grade">
                                    </telerik:GridBoundColumn>
                                    <telerik:GridTemplateColumn HeaderText="grade" UniqueName="grade">
                                        <ItemTemplate>
                                            <telerik:RadNumericTextBox ID="txt_grade" runat="server" Text='<%# Bind("grade") %>'>
                                               <ClientEvents OnValueChanged="txt_grade_value_changed" />
                                            </telerik:RadNumericTextBox>
                                            <asp:HiddenField ID="hd_type" runat="server" Value='<%# Bind("type") %>' />
                                            <asp:HiddenField ID="hd_parent_id" runat="server" Value='<%# Bind("parent_id") %>' />
                                            <asp:HiddenField ID="hd_ass_id" runat="server" Value='<%# Bind("assessment_parameter_id") %>' />
                                            <asp:HiddenField ID="hd_child_count" runat="server" Value='<%# Bind("child_count") %>' />
                                        </ItemTemplate>
                                    </telerik:GridTemplateColumn>
                                </Columns>
                                <DetailTables>
                                    <telerik:GridTableView runat="server" Name="ChequeListDetail" Dir="RTL"  DataKeyNames="assessment_parameter_id"
                                        HierarchyLoadMode="Client" NoDetailRecordsText="it hasn't child"
                                        Font-Names="Tahoma">
                                        <ParentTableRelation>
                                            <telerik:GridRelationFields DetailKeyField="parent_id" MasterKeyField="assessment_parameter_id" />
                                        </ParentTableRelation>
                                        <HeaderStyle HorizontalAlign="Center" CssClass="detailTableLevel2" />
                                        <Columns>
                                            <telerik:GridTemplateColumn HeaderText="cheque_list_id" UniqueName="cheque_list_id"
                                                Visible="false">
                                                <ItemTemplate>
                                                    <asp:Label ID="lbl_cheque_list_id" runat="server" Text='<%# Bind("cheque_list_id") %>' />
                                                </ItemTemplate>
                                                <HeaderStyle Width="50px" />
                                                <ItemStyle Width="50px" />
                                            </telerik:GridTemplateColumn>
                                            <telerik:GridTemplateColumn HeaderText="assessment_parameter_id" UniqueName="assessment_parameter_id"
                                                Visible="false">
                                                <ItemTemplate>
                                                    <asp:Label ID="lbl_assessment_parameter_id" runat="server" Text='<%# Bind("assessment_parameter_id") %>' />
                                                </ItemTemplate>
                                                <HeaderStyle Width="50px" />
                                                <ItemStyle Width="50px" />
                                            </telerik:GridTemplateColumn>
                                            <telerik:GridTemplateColumn HeaderText="parent_id" UniqueName="parent_id" Visible="false">
                                                <ItemTemplate>
                                                    <asp:Label ID="lbl_parent_id" runat="server" Text='<%# Bind("parent_id") %>' />
                                                </ItemTemplate>
                                                <HeaderStyle Width="50px" />
                                                <ItemStyle Width="50px" />
                                            </telerik:GridTemplateColumn>
                                            <telerik:GridTemplateColumn HeaderText="child_count" UniqueName="child_count" Visible="false">
                                                <ItemTemplate>
                                                    <asp:Label ID="lbl_child_count" runat="server" Text='<%# Bind("child_count") %>' />
                                                </ItemTemplate>
                                            </telerik:GridTemplateColumn>
                                            <telerik:GridTemplateColumn HeaderText="type" UniqueName="type" Visible="false">
                                                <ItemTemplate>
                                                    <asp:Label ID="lbl_type" runat="server" Text='<%# Bind("type") %>' />
                                                </ItemTemplate>
                                            </telerik:GridTemplateColumn>
                                            <telerik:GridBoundColumn DataField="assessment_parameter_code" EmptyDataText="----"
                                                HeaderText="assessment_parameter_code" Resizable="true" UniqueName="assessment_parameter_code">
                                            </telerik:GridBoundColumn>
                                            <telerik:GridBoundColumn DataField="parameter_name" EmptyDataText="----" HeaderText="parameter_name"
                                                Resizable="true" UniqueName="parameter_name">
                                            </telerik:GridBoundColumn>
                                            <telerik:GridBoundColumn DataField="max_grade" EmptyDataText="----" HeaderText="max_grade"
                                                Resizable="true" UniqueName="max_grade">
                                            </telerik:GridBoundColumn>
                                            <telerik:GridTemplateColumn HeaderText="grade" UniqueName="grade">
                                                <ItemTemplate>
                                                    <telerik:RadNumericTextBox ID="txt_grade" runat="server" Text='<%# Bind("grade") %>'>
                                                       <ClientEvents OnValueChanged="txt_grade_value_changed" />
                                                    </telerik:RadNumericTextBox>
                                                    <asp:HiddenField ID="hd_type" runat="server" Value='<%# Bind("type") %>' />
                                                    <asp:HiddenField ID="hd_parent_id" runat="server" Value='<%# Bind("parent_id") %>' />
                                                    <asp:HiddenField ID="hd_ass_id" runat="server" Value='<%# Bind("assessment_parameter_id") %>' />
                                                    <asp:HiddenField ID="hd_child_count" runat="server" Value='<%# Bind("child_count") %>' />
                                                </ItemTemplate>
                                            </telerik:GridTemplateColumn>
                                        </Columns>
                                    </telerik:GridTableView>
                                </DetailTables>
                            </telerik:GridTableView>
                        </DetailTables>
                        <NoRecordsTemplate>
                             
                        </NoRecordsTemplate>
                        <CommandItemSettings ShowAddNewRecordButton="false" />
                        <ExpandCollapseColumn Visible="True" ExpandImageUrl="Images/plus.png" CollapseImageUrl="Images/minus.png"
                            ButtonType="ImageButton">
                        </ExpandCollapseColumn>
                        <Columns>
                            <telerik:GridTemplateColumn HeaderText="cheque_list_id" UniqueName="cheque_list_id"
                                Visible="false">
                                <ItemTemplate>
                                    <asp:Label ID="lbl_cheque_list_id" runat="server" Text='<%# Bind("cheque_list_id") %>' />
                                </ItemTemplate>
                            </telerik:GridTemplateColumn>
                            <telerik:GridTemplateColumn HeaderText="parent_id" UniqueName="parent_id" Visible="false">
                                <ItemTemplate>
                                    <asp:Label ID="lbl_parent_id" runat="server" Text='<%# Bind("parent_id") %>' />
                                </ItemTemplate>
                            </telerik:GridTemplateColumn>
                            <telerik:GridTemplateColumn HeaderText="child_count" UniqueName="child_count" Visible="false">
                                <ItemTemplate>
                                    <asp:Label ID="lbl_child_count" runat="server" Text='<%# Bind("child_count") %>' />
                                </ItemTemplate>
                            </telerik:GridTemplateColumn>
                            <telerik:GridTemplateColumn HeaderText="type" UniqueName="type" Visible="false">
                                <ItemTemplate>
                                    <asp:Label ID="lbl_type" runat="server" Text='<%# Bind("type") %>' />
                                </ItemTemplate>
                            </telerik:GridTemplateColumn>
                            <telerik:GridBoundColumn DataField="assessment_parameter_code" EmptyDataText="----"
                                HeaderText="assessment_parameter_code" Resizable="true" UniqueName="assessment_parameter_code">
                            </telerik:GridBoundColumn>
                            <telerik:GridBoundColumn DataField="parameter_name" EmptyDataText="----" HeaderText="parameter_name"
                                Resizable="true" UniqueName="parameter_name">
                            </telerik:GridBoundColumn>
                            <telerik:GridBoundColumn DataField="max_grade" EmptyDataText="----" HeaderText="max_grade"
                                Resizable="true" UniqueName="max_grade">
                            </telerik:GridBoundColumn>
                            <telerik:GridTemplateColumn HeaderText="grade" UniqueName="grade">
                                <ItemTemplate>
                                    <telerik:RadNumericTextBox ID="txt_grade" runat="server" Text='<%# Bind("grade") %>'>
                                    </telerik:RadNumericTextBox>
                                </ItemTemplate>
                            </telerik:GridTemplateColumn>
                        </Columns>
                        <ItemStyle HorizontalAlign="Center" />
                        <HeaderStyle HorizontalAlign="Center" />
                    </MasterTableView>
                    <ClientSettings EnableRowHoverStyle="true" EnablePostBackOnRowClick="true">
                        <Resizing AllowColumnResize="True" ResizeGridOnColumnResize="false" />
                    </ClientSettings>
                </telerik:RadGrid>
 

and in client side i write this function:
<script language="JavaScript1.2" type="text/javascript">
    function txt_grade_value_changed(sender, args) {
        debugger;
        var newValue = args.get_newValue();
        var oldValue = args.get_oldValue();
      //  var d_i = sender.get_parent().get_dataItems();
  
  
        var curr_tr = $('input[id="' + sender._clientID + '"]').closest("tr"); 
        var father_tr = $('input[id="' + sender._clientID + '"]').closest("table").closest("tr").prev();
  
        var father_max_grade = father_tr[0].cells[3].innerText;
  
        if (newValue > curr_max_grade)
            alert('You can continueenter thistory grade');
  
  
  
        var current_grade = 0;
  
        try {
            current_grade = $(curr_tr[0].cells[3].children[0]).closest("span")[0].children[0].value; 
            var parent_id = curr_tr[0].cells[3].children[2].value;
            var curr_id = curr_tr[0].cells[3].children[3].value;
            var curr_max_grade = curr_tr[0].cells[2].innerText;
  
        }
        catch (Error) {
  
            current_grade = $(curr_tr[0].cells[4].children[0]).closest("span")[0].children[0].value;
            var parent_id = curr_tr[0].cells[4].children[2].value;
            var curr_id = curr_tr[0].cells[4].children[3].value;
            var curr_max_grade = curr_tr[0].cells[3].innerText;
  
        }
  
        var father_grade_txt = $(father_tr[0].cells[4].children[0]).closest("span")[0].children[0];
  
        var child_row_array = new Array(10);
        var i = 0;
        var curr_tr2 = curr_tr;
  
        child_row_array[i] = curr_tr;
        i++;
  
        try {
            do {
                if (curr_tr2[0] != undefined && curr_tr2[0].cells[3].children[2].value != undefined && curr_tr2[0].cells[3].children[2].value == parent_id && curr_tr2[0].cells[3].children[3].value != curr_id) {
  
                    child_row_array[i] = curr_tr2;
                    i++;
                }
                curr_tr2 = curr_tr2.next('tr');
  
  
            } while (curr_tr2 && curr_tr2[0] && curr_tr2[0].cells[3].children[2].value != undefined && curr_tr2[0].cells[3].children[3].value != curr_id)
  
            curr_tr2 = curr_tr;
  
            do {
                if (curr_tr2[0] != undefined && curr_tr2[0].cells[3].children[2].value != undefined && curr_tr2[0].cells[3].children[2].value == parent_id && curr_tr2[0].cells[3].children[3].value != curr_id) {
  
                    child_row_array[i] = curr_tr2;
                    i++;
                }
                curr_tr2 = curr_tr2.prev('tr');
  
            } while (curr_tr2 && curr_tr2[0] && curr_tr2[0].cells[3].children[2].value != undefined && curr_tr2[0].cells[3].children[3].value != curr_id)
        }
        catch (Error) {
            try {
                do {
  
                    if (curr_tr2[0] != undefined && curr_tr2[0].cells[4].children[2].value != undefined && curr_tr2[0].cells[4].children[2].value == parent_id && curr_tr2[0].cells[4].children[3].value != curr_id) {
  
                        child_row_array[i] = curr_tr2;
                        i++;
                    }
                    curr_tr2 = curr_tr2.next('tr');
  
  
                } while (curr_tr2 && curr_tr2[0] && curr_tr2[0].cells[4].children[2].value != undefined && curr_tr2[0].cells[4].children[3].value != curr_id)
            }
            catch (Error) {
            }
  
            curr_tr2 = curr_tr;
            try {
                do {
                    if (curr_tr2[0] != undefined && curr_tr2[0].cells[4].children[2].value != undefined && curr_tr2[0].cells[4].children[2].value == parent_id && curr_tr2[0].cells[4].children[3].value != curr_id) {
  
                        child_row_array[i] = curr_tr2;
                        i++;
                    }
                    curr_tr2 = curr_tr2.prev('tr');
  
                } while (curr_tr2 && curr_tr2[0] && curr_tr2[0].cells[4].children[2].value != undefined && curr_tr2[0].cells[4].children[3].value != curr_id)
            }
            catch (Error) {
            }
        }
        var array_lenght = i;
        var count = 0;
        var sum = 0.00;
    
        for (var i = 0; i < array_lenght; i++) {
            try {
                if (child_row_array[i][0].cells[3].firstChild.childNodes[0].value != "")
                    sum = sum + parseFloat(child_row_array[i][0].cells[3].firstChild.childNodes[0].value);
            }
            catch (Error) {
                if (child_row_array[i][0].cells[4].firstChild.childNodes[0].value != "")
                    sum = sum + parseFloat(child_row_array[i][0].cells[4].firstChild.childNodes[0].value);
            }
        }
  
        father_grade_txt.value = sum;
  
  
  
    }
  
</script>


but it has error on finde brothers row.

how can I do that easily?
how can I find brothers of a row and calculate sum of their grade?

1 Answer, 1 is accepted

Sort by
0
Jayesh Goyani
Top achievements
Rank 2
answered on 12 Jun 2012, 12:51 PM
Tags
Grid
Asked by
samaneh
Top achievements
Rank 1
Answers by
Jayesh Goyani
Top achievements
Rank 2
Share this question
or