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

grid rows find in java script

11 Answers 112 Views
Grid
This is a migrated thread and some comments may be shown as answers.
mohamed
Top achievements
Rank 1
mohamed asked on 15 Sep 2011, 01:07 PM
Hello every one
how to find radgrid rows length in javascript here my script

i'm passing through grid like from server side

PricePerUnit.Attributes.Add("onFocusout", "return AmountCalculation('" + RadGrid1.ClientID + "','" + Quantity.ClientID + "','" + PricePerUnit.ClientID + "','" + Amount.ClientID + "','" + subtoal.ClientID + "')");

function AmountCalculation(Grid, Quantity, PricePerUnit, Amount, subtoal) {
                debugger;
                var Grid = $find(Grid);
                var Quantity = $find(Quantity).get_value();
                var PricePerUnit = $find(PricePerUnit).get_value();
                var Amount = $find(Amount);
                var subtotal = $find(subtoal);
 
 
                Amount.set_value(Quantity * PricePerUnit);
 
                for (j = 1; j <= Grid.MasterTableView.length; j++) {
                    if (Quantity.value != "") {
                        subtotal.set_value = Amount;
                    }
                }
            }
please refer the image ,
amount columns value should in assigned in subtotal field ,

Thanks ,
Mohamed.

11 Answers, 1 is accepted

Sort by
0
Jayesh Goyani
Top achievements
Rank 2
answered on 15 Sep 2011, 01:13 PM
Hello,

This method give sum of particuler column.

You can also do like...

 <telerik:GridTemplateColumn  >
                                                    <ItemTemplate>
                                                        <telerik:RadNumericTextBox ID="txtImpression"  runat="server"
                                                            IncrementSettings-InterceptArrowKeys="false"
                                                            IncrementSettings-InterceptMouseWheel="false" MinValue="0" NumberFormat-DecimalDigits="0"
                                                            ClientEvents-OnError="onErrorOccur" onchange="javascript:CalculateCurrentlyAssigned(this);"
                                                            gname="txtImpressions" GroupName='<%# Eval("Name") %>'>
                                                        </telerik:RadNumericTextBox>
                                                    </ItemTemplate>
                                                </telerik:GridTemplateColumn>



function CalculateCurrentlyAssigned(obj) {
                    var SumImpressions = 0
                    $("input[gname='txtImpressions']").each(function () {
                        if ($(this).val() == '') {
                            $(this).val(0);
                        }
                        SumImpressions = SumImpressions + parseInt($(this).val().replace(/,/gi, ""));
                    });
}

by this code you can get sum of  RadNumericTextBox's value. by using jquery

or

If you want to get particular row's controls in client side then check below link
http://www.telerik.com/community/forums/aspnet-ajax/grid/set-controls-attribute-like-enable-disable-on-insert-edit-mode-using-jquery.aspx


let me know if any concern.

Thanks,
Jayesh Goyani
0
mohamed
Top achievements
Rank 1
answered on 16 Sep 2011, 05:03 AM
Hello ,

Amount.set_value(Quantity * PricePerUnit);
how to assign set_value in one variable ,
any other idea to find radgrid length ,
 for (j = 1; j <= Grid.rows.length; j++)

Thanks,
Mohamed.
0
Jayesh Goyani
Top achievements
Rank 2
answered on 16 Sep 2011, 06:43 AM
Hello,

$find("<%= RadGrid1.ClientID %>").get_masterTableView().get_dataItems().length;
or
$find("<%= RadGrid1.ClientID %>").get_masterTableView()._dataSource.length

let me know if any concern.

Thanks,
Jayesh Goyani
0
mohamed
Top achievements
Rank 1
answered on 16 Sep 2011, 01:40 PM
Hello Jayesh Goyani ,

Nothing happen same like that ,

I find the length and calculate the subtotal ,
that's why i want find the length .

This's my aspx page code for radgrid
<telerik:RadGrid ID="RadGrid1" runat="server" OnItemDataBound="RadGrid1_ItemDataBound"
                                            Skin="Office2007" OnItemCreated="RadGrid1_ItemCreated">
                                            <MasterTableView AutoGenerateColumns="False" IsFilterItemExpanded="false">
                                                <CommandItemSettings ExportToPdfText="Export to PDF"></CommandItemSettings>
                                                <RowIndicatorColumn FilterControlAltText="Filter RowIndicator column">
                                                </RowIndicatorColumn>
                                                <ExpandCollapseColumn FilterControlAltText="Filter ExpandColumn column">
                                                </ExpandCollapseColumn>
                                                <Columns>
                                                    <telerik:GridTemplateColumn HeaderText="S.No">
                                                        <ItemTemplate>
                                                            <asp:Label ID="Sno" runat="server" Text="Label" Width="35px" Style="text-align: center">
                                                            </asp:Label>
                                                        </ItemTemplate>
                                                    </telerik:GridTemplateColumn>
                                                    <telerik:GridTemplateColumn HeaderText="Item No">
                                                        <ItemTemplate>
                                                            <telerik:RadNumericTextBox ID="ItemCode" runat="server" Width="120px">
                                                            </telerik:RadNumericTextBox>
                                                        </ItemTemplate>
                                                    </telerik:GridTemplateColumn>
                                                    <telerik:GridTemplateColumn HeaderText="Work Description">
                                                        <ItemTemplate>
                                                            <telerik:RadTextBox ID="Workdesc" runat="server" Width="350px">
                                                            </telerik:RadTextBox>
                                                        </ItemTemplate>
                                                    </telerik:GridTemplateColumn>
                                                    <telerik:GridTemplateColumn HeaderText="Unit">
                                                        <ItemTemplate>
                                                            <telerik:RadComboBox ID="Radcombo_Unit" runat="server" AutoPostBack="true" AppendDataBoundItems="true"
                                                                Width="75%">
                                                            </telerik:RadComboBox>
                                                        </ItemTemplate>
                                                    </telerik:GridTemplateColumn>
                                                    <telerik:GridTemplateColumn HeaderText="Quantity ">
                                                        <ItemTemplate>
                                                            <telerik:RadNumericTextBox ID="Quantity" runat="server" Width="50px">
                                                            </telerik:RadNumericTextBox>
                                                        </ItemTemplate>
                                                    </telerik:GridTemplateColumn>
                                                    <telerik:GridTemplateColumn HeaderText="Price/Unit ">
                                                        <ItemTemplate>
                                                            <telerik:RadNumericTextBox ID="Rate" runat="server" Width="50px">
                                                            </telerik:RadNumericTextBox>
                                                        </ItemTemplate>
                                                    </telerik:GridTemplateColumn>
                                                    <telerik:GridTemplateColumn HeaderText="Amount ">
                                                        <ItemTemplate>
                                                            <telerik:RadNumericTextBox ID="Amount" runat="server" Width="60px">
                                                            </telerik:RadNumericTextBox>
                                                        </ItemTemplate>
                                                    </telerik:GridTemplateColumn>
                                                    <telerik:GridTemplateColumn HeaderText="Fees">
                                                        <ItemTemplate>
                                                            <telerik:RadNumericTextBox ID="Fees" runat="server" Width="65px">
                                                            </telerik:RadNumericTextBox>
                                                        </ItemTemplate>
                                                    </telerik:GridTemplateColumn>
                                                    <telerik:GridTemplateColumn HeaderText="Total">
                                                        <ItemTemplate>
                                                            <telerik:RadNumericTextBox ID="Total" runat="server" Width="65px">
                                                            </telerik:RadNumericTextBox>
                                                        </ItemTemplate>
                                                    </telerik:GridTemplateColumn>
                                                </Columns>
                                                <EditFormSettings>
                                                    <EditColumn FilterControlAltText="Filter EditCommandColumn column">
                                                    </EditColumn>
                                                </EditFormSettings>
                                            </MasterTableView>
                                            <ClientSettings EnablePostBackOnRowClick="false" AllowDragToGroup="true">
                                                <Selecting AllowRowSelect="true" />
                                            </ClientSettings>
                                            <FilterMenu EnableImageSprites="False">
                                            </FilterMenu>
                                            <HeaderContextMenu CssClass="GridContextMenu GridContextMenu_">
                                            </HeaderContextMenu>
                                        </telerik:RadGrid>


This My .cs page

private DataTable tabledata1
       {
           get
           {
               DataTable dt = (DataTable)Session["QuotationAdd"];
 
               if (dt == null)
               {
                   dt = new DataTable();
                   object[] emptyrow = new object[columcount];
                   dt.Columns.Add("Sno", typeof(string));
                   dt.Columns.Add("ItemCode", typeof(string));
                   dt.Columns.Add("Workdesc", typeof(string));
                   dt.Columns.Add("Radcombo_Unit", typeof(string));
                   dt.Columns.Add("Quantity", typeof(string));
                   dt.Columns.Add("Rate", typeof(string));
                   dt.Columns.Add("Amount", typeof(string));
                   dt.Columns.Add("Fees", typeof(string));
                   dt.Columns.Add("Total", typeof(string));
 
                   for (int i = 1; i < rowcount + 1; i++)
                   {
                       emptyrow[0] = i.ToString();
                       dt.Rows.Add(emptyrow);
                   }
                   tabledata1 = dt;
               }
               return dt;
           }
           set
           {
               Session["QuotationAdd"] = value;
           }
       }
 
       private void assigndt2(DataTable dt)
       {
           RadTextBox t1;
           Label l1;
           for (int i = 0; i <= RadGrid1.Items.Count - 1; i++)
           {
               if (dt.Rows.Count - 1 < i)
               {
                   object[] emptyRow = new object[columcount];
                   dt.Rows.Add(emptyRow);
               }
           }
       }

In page load i call like that
                tabledata1 = null;
                this.RadGrid1.DataSource = tabledata1;
                this.RadGrid1.DataBind();

please reply as soon as possible

Thanks,
Mohamed.
0
Accepted
Jayesh Goyani
Top achievements
Rank 2
answered on 19 Sep 2011, 07:10 AM
Hello,


<telerik:RadGrid ID="RadGrid1" runat="server" AutoGenerateColumns="false" OnNeedDataSource="RadGrid1_NeedDataSource">
    <MasterTableView>
        <Columns>
            <telerik:GridBoundColumn DataField="ID" HeaderText="ID" UniqueName="ID">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="Name" HeaderText="Name" UniqueName="Name">
            </telerik:GridBoundColumn>
            <telerik:GridTemplateColumn HeaderText="Quantity">
                <ItemTemplate>
                <telerik:RadNumericTextBox  ID="RadNumericTextBox1" runat="server"></telerik:RadNumericTextBox>
                </ItemTemplate>
            </telerik:GridTemplateColumn>
            <telerik:GridTemplateColumn HeaderText="Rate">
                <ItemTemplate>
                <telerik:RadNumericTextBox  ID="RadNumericTextBox2" runat="server"></telerik:RadNumericTextBox>
                </ItemTemplate>
            </telerik:GridTemplateColumn>
            <telerik:GridTemplateColumn HeaderText="Amount">
                <ItemTemplate>
                <telerik:RadNumericTextBox  ID="RadNumericTextBox3" runat="server"></telerik:RadNumericTextBox>
                </ItemTemplate>
            </telerik:GridTemplateColumn>
        </Columns>
    </MasterTableView>
</telerik:RadGrid>
<telerik:RadCodeBlock ID="RadCodeBlock1" runat="server">
    <script type="text/javascript">
        function GetInfo() {
            
            var grid = $find("<%=RadGrid1.ClientID %>");
            var MasterTable = grid.get_masterTableView();
            var Rows = MasterTable.get_dataItems();
            for (var i = 0; i < Rows.length; i++) {
                var row = Rows[i];
                var RadNumericTextBox1 = row.findControl("RadNumericTextBox1");
                var RadNumericTextBox2 = row.findControl("RadNumericTextBox2");
                var RadNumericTextBox3 = row.findControl("RadNumericTextBox3");
 
                RadNumericTextBox3.set_value(RadNumericTextBox1.get_value() * RadNumericTextBox2.get_value());
            }
        }
    </script>
</telerik:RadCodeBlock>

 <asp:Button ID="Button1" runat="server" OnClientClick="GetInfo(); return false;"
            Text="Button" />

let me know if any concern.

Thanks,
Jayesh Goyani
0
mohamed
Top achievements
Rank 1
answered on 19 Sep 2011, 08:20 AM
Thanks Alot Jayesh Goyani



Thanks,
Mohamed.
0
Bhumesh
Top achievements
Rank 1
answered on 16 Jul 2013, 11:56 AM
  var JobsiteManagerGridView = document.getElementById('ctl00_ContentPlaceHolder1_radgrdJobsiteMgr');
       
        if ((JobsiteManagerGridView != null) && (typeof JobsiteManagerGridView != "undefined")) {
            var rowcount= JobsiteManagerGridView.get_masterTableView().get_dataItems().length;
               
}
any one please help me 
am not getting grid row count in client side code
the above code in external javascript file 


         
0
Princy
Top achievements
Rank 1
answered on 16 Jul 2013, 12:27 PM
Hi Bhumesh,

Please try the below code to get the rows count.

ASPX:
<telerik:RadGrid ID="RadGrid1" runat="server" >
    <MasterTableView>     
        <Columns>
          . . . . . . . .
        </Columns>
    </MasterTableView
        <ClientEvents OnRowClick="RowCount" /> 
    </ClientSettings>
</telerik:RadGrid>

JS:
<script type="text/javascript">
  function RowCount() {
    var grid = $find("<%=RadGrid1.ClientID %>");
    var MasterTable = grid.get_masterTableView();
    var Rows = MasterTable.get_dataItems();
    alert(Rows.length);
    }
</script>

Thanks,
Princy
0
Bhumesh
Top achievements
Rank 1
answered on 16 Jul 2013, 12:39 PM
Hi Princy 
thanks for your response 
i dont want this in row click event ,here i need to show markers in map on page load event  according to the grid having latitude and longitudes

thanks 
 
0
Bhumesh
Top achievements
Rank 1
answered on 16 Jul 2013, 12:50 PM
its working for me...
var JobsiteManagerGridView = document.getElementById('ctl00_ContentPlaceHolder1_radgrdJobsiteMgr_ctl00');
        
        if ((JobsiteManagerGridView != null) && (typeof JobsiteManagerGridView != "undefined")) {
            var rowcount= JobsiteManagerGridView.rows.length;
                
}
thanks
0
Jayesh Goyani
Top achievements
Rank 2
answered on 16 Jul 2013, 01:45 PM
Hello,

protected void Page_PreRender(object sender, System.EventArgs e)
    {
        if (!IsPostBack)
        {
            Page.ClientScript.RegisterStartupScript(this.GetType(), "Script123", "RowCount();", true);
            //OR
            ScriptManager.RegisterStartupScript(this, this.GetType(), "Script123", "RowCount();", true);
        }
    }

Please call this function above page method.

May be you trying to access row count before your grid bind.

Thanks,
Jayesh Goyani
Tags
Grid
Asked by
mohamed
Top achievements
Rank 1
Answers by
Jayesh Goyani
Top achievements
Rank 2
mohamed
Top achievements
Rank 1
Bhumesh
Top achievements
Rank 1
Princy
Top achievements
Rank 1
Share this question
or