I have a button in radgrid(pager template) with class "FirstPage", and I want to register onclick event for button with JQuery, so I wrote this code.
in first load everything is Ok, but when grid data is changed(page index change or filter data or...). registered event is losed.
any idea?
Thank.
| $(function() { |
| $(':button.FirstPage').click(function() { goFirstPage(); }); |
| }); |
in first load everything is Ok, but when grid data is changed(page index change or filter data or...). registered event is losed.
any idea?
Thank.
5 Answers, 1 is accepted
0
Hi Mojtaba,
Try binding the event handler as explained in the following documentation article:
http://docs.jquery.com/Events/bind#typedatafn
and if the problem persists, could you paste your aspx and code-behind. Please, use the Code Formatter tool of the html editor.
Thank you.
Best wishes,
Tsvetoslav
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Try binding the event handler as explained in the following documentation article:
http://docs.jquery.com/Events/bind#typedatafn
and if the problem persists, could you paste your aspx and code-behind. Please, use the Code Formatter tool of the html editor.
Thank you.
Best wishes,
Tsvetoslav
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Mojtaba
Top achievements
Rank 1
answered on 25 Aug 2009, 06:10 AM
I understood that when I register a style or event or anything for a control in grid via document.ready(JQuery), is loosed when new data is loaded(page index change,filtering,sorting,.....), so I write new simple scenario:
My grid direction is right to left(dir=rtl), but I want to set first filter box to left to right, so I wrote this JQuey code.
In first load everything is Ok, but when I sort column(or change page index or...), filter box direction is right to left.
My grid code is:
I wrote this code for item command:
Thanks.
My grid direction is right to left(dir=rtl), but I want to set first filter box to left to right, so I wrote this JQuey code.
| $(function() { |
| var box= $('.rgFilterBox:first'); |
| if (box.size() > 0) { |
| box.attr('dir', 'ltr'); |
| } |
| }); |
In first load everything is Ok, but when I sort column(or change page index or...), filter box direction is right to left.
My grid code is:
| <asp:UpdatePanel ID="updatePanel5" runat="server"> |
| <ContentTemplate> |
| <telerik:RadGrid runat="server" ID="grdFinancialPeriods" Width="99%" HorizontalAlign="Center"> |
| <MasterTableView DataKeyNames="IdPrd" ClientDataKeyNames="IdPrd"> |
| <Columns> |
| <telerik:GridBoundColumn HeaderText="ردیف" UniqueName="RowNo" DataType="System.Double" |
| AllowFiltering="false"> |
| </telerik:GridBoundColumn> |
| <telerik:GridBoundColumn DataField="IdPrd" HeaderText="ID" DataType="System.Double" |
| Visible="false"> |
| </telerik:GridBoundColumn> |
| <telerik:GridBoundColumn DataField="CuPrd" HeaderText="کد" DataType="System.String"> |
| </telerik:GridBoundColumn> |
| <telerik:GridBoundColumn DataField="DscPrd" HeaderText="نام دوره" DataType="System.String"> |
| </telerik:GridBoundColumn> |
| <telerik:GridBoundColumn DataField="AbrPrd" HeaderText="مخفف" DataType="System.String" |
| FilterListOptions="VaryByDataType"> |
| </telerik:GridBoundColumn> |
| <telerik:GridTemplateColumn FilterControlWidth="120px" DataField="Dt_Prd_From_M" |
| UniqueName="Dt_Prd_From_M" HeaderText="تاریخ شروع" SortExpression="Dt_Prd_From_M"> |
| <ItemTemplate> |
| <asp:Label ID="lblStartDate" Text='<% #(Convert.ToDateTime(Eval("Dt_Prd_From_M"))).ToPersianDate().ToShortString()%>' |
| runat="server" Style="direction: ltr"></asp:Label> |
| </ItemTemplate> |
| </telerik:GridTemplateColumn> |
| <telerik:GridTemplateColumn FilterControlWidth="120px" DataField="Dt_Prd_To_M" UniqueName="Dt_Prd_To_M" |
| HeaderText="تاریخ پایان" SortExpression="Dt_Prd_To_M"> |
| <ItemTemplate> |
| <asp:Label ID="lblEndDate" Text='<% #(Convert.ToDateTime(Eval("Dt_Prd_To_M"))).ToPersianDate().ToShortString()%>' |
| runat="server"></asp:Label> |
| </ItemTemplate> |
| </telerik:GridTemplateColumn> |
| <telerik:GridButtonColumn ButtonType="LinkButton" Text='<%$Resources: Common, AssignText %>' |
| UniqueName="EditColumn" HeaderText="اختصاص محل تابعه" CommandName="Assign"> |
| </telerik:GridButtonColumn> |
| <telerik:GridButtonColumn ButtonType="LinkButton" Text='<%$Resources: Common, EditText %>' |
| UniqueName="EditColumn" HeaderText="ویرایش" CommandName="Editing"> |
| </telerik:GridButtonColumn> |
| <telerik:GridButtonColumn ConfirmTitle="حذف" ConfirmDialogType="RadWindow" ConfirmText="رکورد حذف شود؟" |
| ButtonType="LinkButton" CommandName="Delete" Text='<%$Resources: Common, DeleteText %>' |
| UniqueName="DeleteColumn" HeaderText="حذف"> |
| </telerik:GridButtonColumn> |
| </Columns> |
| <PagerTemplate> |
| <table class="PagerPanel" width="98%" align="center"> |
| <tr> |
| <td class="pagerDivFirstPage" width="20" align="left"> |
| <input type="button" class="FirstPage" causesvalidation="false" /> |
| </td> |
| <td class="pagerDivPageNumber" width="120"> |
| |
| صفحه : |
| |
| <input type="text" style="width:20px;" class="pagerTextBox" /> |
| |
| از |
| <label class="PagerCount" /> |
| </td> |
| <td class="pagerDivLastPage" width="70" align="right"> |
| <input type="button" class="LastPage" causesvalidation="false" /> |
| </td> |
| <td> |
| <asp:Panel runat="server" ID="NumericPagerPlaceHolder"/> |
| </td> |
| <td class="pagerDivDescription" width="120" align="left"> |
| <label class="PagerDesc" /> |
| </td> |
| </tr> |
| </table> |
| </PagerTemplate> |
| <PagerStyle Mode="NumericPages" AlwaysVisible="true" /> |
| </MasterTableView> |
| </telerik:RadGrid> |
| </ContentTemplate> |
| </asp:UpdatePanel> |
I wrote this code for item command:
| void grdFinancialPeriods_ItemCommand(object source, GridCommandEventArgs e) |
| { |
| #region Page |
| else if (e.CommandName == "Page") |
| { |
| grdFinancialPeriods.MasterTableView.CurrentPageIndex = Convert.ToInt32(e.CommandArgument) - 1; |
| } |
| #endregion |
| #region Filter |
| else if (e.CommandName == "Filter") |
| { |
| Pair filterPair = e.CommandArgument as Pair; |
| TextBox filterBox = (e.Item as GridFilteringItem)[filterPair.Second.ToString()].Controls[0] as TextBox; |
| string[] filterParams = filterBox.Text.Trim().Split(' '); |
| FilterTypes filterType = (FilterTypes)Enum.Parse(typeof(FilterTypes), Convert.ToString(filterPair.First)); |
| FilterItemList filterItemList; |
| if (Session["filterItemList"] == null) |
| { |
| filterItemList = new FilterItemList(); |
| } |
| else |
| { |
| filterItemList = (FilterItemList)Session["filterItemList"]; |
| } |
| FilterItem filterItem = new FilterItem(Convert.ToString(filterPair.Second), filterType, |
| filterParams.Length > 0 ? filterParams[0] : "", filterParams.Length == 2 ? filterParams[1] : "", |
| filterPair.Second.ToString() == "Dt_Prd_From_M" || filterPair.Second.ToString() == "Dt_Prd_To_M" ? FieldType.DateTime : FieldType.String); |
| filterItemList.Add(filterItem); |
| filterBox.Text = filterItem.FirstParameter + " " + filterItem.SecondParameter; |
| Session["filterItemList"] = filterItemList; |
| } |
| #endregion |
| #region Sort |
| else if (e.CommandName == "Sort") |
| { |
| string sortOrder = ((Telerik.Web.UI.GridSortCommandEventArgs)(e)).NewSortOrder.ToString(); |
| if (sortOrder != "None") |
| { |
| SortTypes sortType = (SortTypes)Enum.Parse(typeof(SortTypes), sortOrder); |
| string fieldName = ((Telerik.Web.UI.GridSortCommandEventArgs)(e)).SortExpression; |
| SortItem sortItem = new SortItem |
| { |
| FieldName = fieldName, |
| SortType = sortType |
| }; |
| Session["SortExpression"] = sortItem; |
| } |
| else |
| { |
| Session["SortExpression"] = null; |
| } |
| } |
| #endregion |
| BindGrid(); |
| } |
| private void BindGrid() |
| { |
| int count = 0; |
| FinancialPeriodManagerClient service = new FinancialPeriodManagerClient(); |
| grdFinancialPeriods.MasterTableView.FilterExpression = string.Empty; |
| Prd[] list = service.GetAllFinancialPeriods(out count, grdFinancialPeriods.PageSize, |
| grdFinancialPeriods.MasterTableView.CurrentPageIndex * grdFinancialPeriods.PageSize, |
| (Behsaman.FilterItemList)Session["filterItemList"], |
| (SortItem)Session["SortExpression"]); |
| grdFinancialPeriods.DataSource = list; |
| grdFinancialPeriods.VirtualItemCount = count; |
| grdFinancialPeriods.DataBind(); |
| service.Close(); |
| } |
Thanks.
0
Mojtaba
Top achievements
Rank 1
answered on 26 Aug 2009, 10:06 AM
Isn't there any answer?
0
Accepted
Hi Mojtaba,
The jQuery code should be working fine if you are executing it in the page_Load event. Please, take a look at the attached sample for comparison with your implementation.
Best wishes,
Tsvetoslav
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
The jQuery code should be working fine if you are executing it in the page_Load event. Please, take a look at the attached sample for comparison with your implementation.
Best wishes,
Tsvetoslav
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Mojtaba
Top achievements
Rank 1
answered on 29 Aug 2009, 07:38 AM
Hi Tsvetoslav,
Thank you for answer.
Thank you for answer.