Excel Like Filtering - using Webservice context is NULL

8 posts, 0 answers
  1. Srikrishna
    Srikrishna avatar
    10 posts
    Member since:
    May 2015

    Posted 12 Apr Link to this post

    W.r.t to Excel like filtering in radgrid. I am trying to call a webservice using - FilterCheckListWebServiceMethod
    Requirement : To use Webservice , I have 40 columns so planning to send Column name as a context to WS method and reuse the select query for all..
    eg) FilterCheckListWebServiceMethod="LoadDistinctValues"

    [WebMethod] public RadComboBoxItemData[] LoadDistinctValues(Dictionary<string, object> context)
    {     
       IDictionary<string, object> contextDictionary = (IDictionary<string, object>)context;
       ........ The following context is NULL

    Sample:
      <telerik:RadGrid ID="rd" runat="server" AllowFilteringByColumn="true" FilterType="HeaderContext" EnableHeaderContextMenu="True"
                             EnableHeaderContextFilterMenu="True" AllowPaging="True" PageSize="35"
                             AllowSorting="true" Width="100%" >
                    <PagerStyle Mode="Slider" Position="TopAndBottom" PageSizes="100,200,400,500" AlwaysVisible="True" />
                    <ClientSettings Scrolling-AllowScroll="true" Scrolling-UseStaticHeaders="true"  EnableRowHoverStyle="true">
                        <DataBinding Location="loadOnDemand.asmx" SortParameterType="Linq" FilterParameterType="Linq">
                        </DataBinding>
                    </ClientSettings>
       <MasterTableView CommandItemDisplay="Top" DataKeyNames="ID" HorizontalAlign="NotSet" EditMode="Batch" AutoGenerateColumns="False"
                                 AllowAutomaticDeletes="False" Font-Size="9" FilterItemStyle-HorizontalAlign="Center" Width="100%"
                                 TableLayout="Fixed" CheckListWebServicePath="loadOnDemand.asmx">

                        <telerik:GridBoundColumn DataField="VERIFIEDBY" HeaderText="Verified By" ColumnEditorID="ceVERIFIEDBY"
                                                 SortExpression="VERIFIEDBY" UniqueName="VERIFIEDBY"
                                                 AutoPostBackOnFilter="true" CurrentFilterFunction="StartsWith"
                                                 FilterControlWidth="80px" HeaderStyle-Width="140px" FilterCheckListWebServiceMethod="LoadDistinctValues"  >
                        </telerik:GridBoundColumn>
  2. Maria Ilieva
    Admin
    Maria Ilieva avatar
    4017 posts

    Posted 15 Apr Link to this post

    Hi,

    Note that using WebMethod as you are trying to achieve in your code would not work in this case. You should use WebService as shown in the online demo below:
    http://demos.telerik.com/aspnet-ajax/listbox/examples/loadondemand/wcf/defaultcs.aspx

    I hope this helps.

    Regards,
    Maria Ilieva
    Telerik
    Do you need help with upgrading your ASP.NET AJAX, WPF or WinForms projects? Check the Telerik API Analyzer and share your thoughts.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Srikrishna
    Srikrishna avatar
    10 posts
    Member since:
    May 2015

    Posted 15 Apr in reply to Maria Ilieva Link to this post

    Thank you for your reply. The example you provided will involve much changes in my side as I have 40 columns and I would like to avoid using radcombo or listbox .. instead of my current gridboundcolumn. That's fine we settled with using multiple methods to achive this scenario.

     

    I have found one more issue in Excel like filtering grid. When select few checkbox and click 'filter' it works fine. But once user tries to reopen the same column and click 'Clear Filter' button . It is not unchecking the checkbox selected by user before. I see that your online demo is working fine but I am not able to replicate that clearing in my side.

     

    Question 1: Is there a way for me to Handle the 'ClearFilter' event in codebehind (or) client side .

    Question 2 : I only want to clear the selected column filter not other remaining columns.

    Question 3 : When I click 'Filter' button - radgrid filters but I don't get to see the loading image. Which shows up on other operations.

     

    Please find the code .. Removed few lines . Please help. Using Vs 2015 enterprise , ,net 4.5.01055

    Telerik : v4.0.30319 ,  version : 2015.3.1111.45 , Telerik UI for ASP.NET AJAX

     

    <%@ Page Title="Line" Language="C#" MasterPageFile="~/masterPages/mechanicalDefault.Master" AutoEventWireup="true" CodeBehind="LineList.aspx.cs" Inherits="Mechanical.LineList.LineList" %>
    <asp:Content ContentPlaceHolderID="cphPageTitle" runat="server">
     Line List
    </asp:Content>
    <asp:Content ContentPlaceHolderID="cphMain" runat="server">
        <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server"  EnablePageHeadUpdate="False" DefaultLoadingPanelID="radlpLineList" UpdatePanelsRenderMode="Inline">
            <ClientEvents OnRequestStart="onRequestStart" />
      <AjaxSettings>
       <telerik:AjaxSetting AjaxControlID="radgLineList">
        <UpdatedControls>
         <telerik:AjaxUpdatedControl ControlID="radgLineList"/>
         <telerik:AjaxUpdatedControl ControlID="msg" />
                           <telerik:AjaxUpdatedControl ControlID="RadWindowManager" />
        </UpdatedControls>
       </telerik:AjaxSetting>
       
      </AjaxSettings>
     </telerik:RadAjaxManager>
     <telerik:RadAjaxLoadingPanel ID="radlpLineList" runat="server" />
     <telerik:RadScriptBlock ID="RadScriptBlock1" runat="server">
      <script type="text/javascript">
          function ShowLineListDetails(ID){
              return openLineListDetailsWindow("<%= ResolveUrl("~/controls/Containers/LineListDetails.aspx") %>?ID=" + ID , "LineListDetailsForm");
          }
          function openLineListDetailsWindow(link, radWindowID){
           var oManager = $find("<%= RadWindowManager.ClientID %>");
           oManager.open(link, radWindowID);
           return false;
          }
          function refreshLineListGrid(sender, eventArgs) {
           var grid = $find("<%= radgLineList.ClientID %>").get_masterTableView();
           grid.rebind();
          }
          function clearDropDownItems(sender, args) {
              if (sender.get_items().get_count() !== 0) {
                  sender.clearItems();
                  sender.hideDropDown();
                  sender.showDropDown();
              }
          }

          function onRequestStart(sender, args) {
              if (args.get_eventTarget().indexOf("ExportTo") >= 0) {
                  args.set_enableAjax(false);
              }
          }
      </script>
     </telerik:RadScriptBlock>
     <telerik:RadWindowManager ID="RadWindowManager" EnableViewState="false" Behaviors="Move,Close,Resize,Maximize" ReloadOnShow="true"
                                  ShowContentDuringLoad="false" VisibleStatusbar="false" KeepInScreenBounds="true" runat="server">
      <Windows>
       <telerik:RadWindow ID="LineListDetailsForm" Height="575px" Width="1300px" Modal="true" runat="server" OnClientClose="refreshPanelListGrid"/>
      </Windows>
            <Windows>
                <telerik:RadWindow runat="server" ID="RadWindow" />
            </Windows>
     </telerik:RadWindowManager>
        <br />
        <asp:Label ID="msg" runat="server" EnableViewState="false" Visible="False" />
     
        <div id="divResults" runat="server" >
            <div id="div1" runat="server" visible="true">
            <div style="float: right;">
                <asp:Literal ID="lblLastSyncUpdated" runat="server"></asp:Literal>
            </div>
            </div>
      <telerik:RadGrid ID="radgLineList" runat="server" PageSize="500" AllowPaging="True" AutoGenerateColumns="False"
                             AllowSorting="true" Width="100%" EnableLinqExpressions="false" GroupingSettings-CaseSensitive="false"
                             EnableHeaderContextFilterMenu="True" EnableHeaderContextMenu="True" AllowFilteringByColumn="true" FilterType="HeaderContext">
                   <ClientSettings Scrolling-AllowScroll="true" Scrolling-UseStaticHeaders="true" />
       <MasterTableView CommandItemDisplay="Top" DataKeyNames="ID" HorizontalAlign="NotSet" EditMode="Batch" AutoGenerateColumns="False"
                                 AllowAutomaticDeletes="False" Font-Size="9" FilterItemStyle-HorizontalAlign="Center" Width="100%"
                                 CheckListWebServicePath="/mechanical/AppServices/loadOnDemand.asmx">
                      <CommandItemSettings ShowRefreshButton="true" />
                      <PagerStyle Mode="NextPrevAndNumeric" AlwaysVisible="True" Position="Bottom" PageSizes="10,15,20,50,100,500,1000" />
        <Columns>
         <telerik:GridButtonColumn ButtonType="ImageButton" UniqueName="cmdDeleteView" CommandName="Delete"
                                                  ConfirmDialogType="RadWindow" ConfirmText="Delete selected record?"
                                                  Text="Delete" ImageUrl="/global/graphics/icons/delete.png"
                                                  FilterCheckListEnableLoadOnDemand="false">
          <HeaderStyle Width="30px"/>
                                <ItemStyle HorizontalAlign="Center" />
         </telerik:GridButtonColumn>



                        <telerik:GridBoundColumn UniqueName="REVISION_NAME" DataField="REVISION_NAME" ColumnEditorID="ceRevision" ReadOnly="true"
                                                 HeaderText="Revision Name" SortExpression="REVISION_NAME"
                                                 FilterControlWidth="50px" HeaderStyle-Width="90px"
                                                 CurrentFilterFunction="StartsWith" FilterCheckListWebServiceMethod="LoadRevisionName"/>
                        <telerik:GridBoundColumn DataField="VERIFIEDBY" HeaderText="Verified By" ColumnEditorID="ceVERIFIEDBY"
                                                 SortExpression="VERIFIEDBY" UniqueName="VERIFIEDBY"
                                                 CurrentFilterFunction="StartsWith" FilterCheckListWebServiceMethod="LoadVerifiedBy"
                                                 FilterControlWidth="80px" HeaderStyle-Width="140px"  FilterCheckListEnableLoadOnDemand="true" >
                        </telerik:GridBoundColumn>

                        <telerik:GridTemplateColumn HeaderText="Nominal Diameter" SortExpression="NOMINALDIAMETER" ColumnEditorID="ceText10"
                                                    HeaderStyle-Width="95px" DataField="NOMINALDIAMETER" UniqueName="NOMINALDIAMETER"
                                                    CurrentFilterFunction="StartsWith" FilterCheckListWebServiceMethod="LoadNominalDiameter">
                            <HeaderStyle Width="95px" />
                           <ItemTemplate>
                                <asp:Literal ID="ltlNOMINALDIAMETER" runat="server" Text='<%# Eval("NOMINALDIAMETER") %>' />
                            </ItemTemplate>
                            <EditItemTemplate>
                                <asp:RequiredFieldValidator ID="rfvNOMINALDIAMETER" ControlToValidate="txtNOMINALDIAMETER" ErrorMessage="!" runat="server" ForeColor="red" Font-Bold="true" Display="Dynamic"></asp:RequiredFieldValidator>
                                <asp:TextBox ID="txtNOMINALDIAMETER" Text='<%# Bind("NOMINALDIAMETER") %>' runat="server" Width="75px"></asp:TextBox>
                            </EditItemTemplate>
                        </telerik:GridTemplateColumn>

                        <telerik:GridBoundColumn UniqueName="SEQUENCENUMBER" DataField="SEQUENCENUMBER" ColumnEditorID="ceSequenceNumber"
                                                 HeaderText="Sequence Number" SortExpression="SEQUENCENUMBER"
                                                 FilterControlWidth="80px" HeaderStyle-Width="140px"
                                                 FilterCheckListEnableLoadOnDemand="false" CurrentFilterFunction="StartsWith" >
                        </telerik:GridBoundColumn>
                        <telerik:GridTemplateColumn UniqueName="PIPECLASS" DataField="PIPECLASS" HeaderText="Pipe Class"
                                                    SortExpression="PIPECLASS" FilterControlWidth="80px" HeaderStyle-Width="140px"
                                                    CurrentFilterFunction="StartsWith" FilterCheckListWebServiceMethod="LoadPipeClass">
                            <ItemTemplate>
                                <%# Eval("PIPECLASS") %>
                            </ItemTemplate>
                            <EditItemTemplate>
                                <asp:RequiredFieldValidator runat="server" ID="rfvPipeClass" ControlToValidate="rcbPipeClass"
                                                            ErrorMessage="!" ForeColor="red" Font-Bold="true" Display="Dynamic"></asp:RequiredFieldValidator>
                                <telerik:RadComboBox ID="rcbPipeClass" runat="server"
                                                     DataTextField="Name" DataValueField="Name" OnItemsRequested="rcbPipeClass_ItemsRequested"
                                                     EnableLoadOnDemand="true" ShowMoreResultsBox="true" AllowCustomText="false"
                                                     DropDownAutoWidth="Enabled" Width="100%" Font-Size="8" OnClientDropDownOpening="clearDropDownItems" />
                            </EditItemTemplate>
                        </telerik:GridTemplateColumn>

        </Columns>
       </MasterTableView>
      </telerik:RadGrid>
     </div>
    </asp:Content>

     

     

     

    CODEBEHIND:;

    using System;
    using System.Data;
    using System.ComponentModel;
    using System.Collections.Generic;
    using System.Text;
    using System.Linq;
    using System.Collections;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using Shell.SIEP.Common;
    using Shell.SIEP.EDD.Mechanical.Common.BasePages;
    using Shell.SIEP.EDD.BusinessLayer.Common;
    using Shell.SIEP.EDD.BusinessLayer.Mechanical;
    using Shell.SIEP.Common.Helpers;
    using Shell.SIEP.Controls.Web;
    using Shell.SIEP.Controls;
    using Shell.SIEP.EDD.Providers.Data;
    using Telerik.Web.UI;
    using System.Web;
    namespace Mechanical.LineList
    {
        public partial class LineList : MechanicalPage
        {
            #region Page Events
            override protected void OnInit(EventArgs e)
            {
                InitializeComponent();
                base.OnInit(e);
            }
            private void InitializeComponent()
            {
                radgLineList.NeedDataSource += radgLineList_NeedDataSource;
                radgLineList.BatchEditCommand += radgLineList_BatchEditCommand;
                radgLineList.ItemCreated += radgLineList_ItemCreated;
                radgLineList.DeleteCommand +=radgLineList_DeleteCommand;
                radgLineList.ItemCommand += radgLineList_ItemCommand;
                radgLineList.Load += radgLineList_Load;
                radgLineList.FilterCheckListItemsRequested += radgLineList_FilterCheckListItemsRequested;
            }
            protected void radgLineList_ItemCommand(object sender, GridCommandEventArgs e)
            {
                switch (e.CommandName)
                {
                    case "Delete":
                        GridEditableItem editedItem = e.Item as GridEditableItem;
                        int pID = 0;
                        StatusInfo status = new StatusInfo();
                        LineListEntity objLineListEntity = new LineListEntity();
                        int.TryParse(((GridDataItem)e.Item).GetDataKeyValue("ID").ToString(), out pID);
                        status = objLineListEntity.Delete(pID, AssetID);
                        if (status.Status)
                            WebControls.MessageWrite(Page, msg, WebControls.MessageDisplayType.Success, "Deleted Successfully", true, true);
                        else
                            WebControls.MessageWrite(Page, msg, WebControls.MessageDisplayType.Problem, string.Format("{0}: {1}", pID, "An error occurred. Unable to update at this time."), true, true);
                        Refresh();
                        break;
                }
            }
            protected void Page_Load(object sender, EventArgs e)
            {
                LoadClientScripts();
                if (!IsPostBack)
                {
                    radtbLineList.DataBind();
                    SetupQuickSearch();
                    GetLastSyncDate();
                }
                GridFilterFunction.IllegalStrings = new string[] { " LIKE ", " AND ", " OR ", " NULL ", " IS " };
            }
            #endregion
            #region Events
            protected void radgLineList_FilterCheckListItemsRequested(object sender, GridFilterCheckListItemsRequestedEventArgs e)
            {
                string dataField = (e.Column as IGridDataColumn).GetActiveDataField();

                switch (SearchType)
                {
                    case SearchType.EasyQuery:
                        e.ListBox.DataSource = GetEasyQueryResults().DefaultView.ToTable(true, dataField);
                        break;
                    case SearchType.QuickSearch:
                        e.ListBox.DataSource = GetQuickSearchResults().DefaultView.ToTable(true, dataField);
                        break;
                }
                e.ListBox.DataKeyField = dataField;
                e.ListBox.DataTextField = dataField;
                e.ListBox.DataValueField = dataField;
                e.ListBox.DataBind();
            }
            protected void radgLineList_NeedDataSource(object source, GridNeedDataSourceEventArgs e)
            {
                switch (SearchType)
                {
                    case SearchType.EasyQuery:
                        radgLineList.DataSource = GetEasyQueryResults();
                        break;
                }
            }

            protected void radgLineList_Load(object sender, EventArgs e)
            {
                RadControls.RadGrid_Common_OnLoad(sender, e, LineListAuthorizedActions);
            }
            protected void radgLineList_ItemCreated(object sender, GridItemEventArgs e)
            {
                RadControls.RadGrid_Common_ItemCreated(sender, e, LineListAuthorizedActions);
            }
            protected void radgLineList_DeleteCommand(object source, GridCommandEventArgs e)
            {
                string ID = e.Item.OwnerTableView.DataKeyValues[e.Item.ItemIndex]["ID"].ToString();
            }

            #endregion 
            #region Private
            private void LoadClientScripts()
            {
                if (!Page.ClientScript.IsClientScriptBlockRegistered(typeof(LineList), "LineListScripts"))
                {
                    StringBuilder jscript = new StringBuilder();
                    jscript.Append("function refreshPanelListGrid(arg){");
                    jscript.Append("var grid = $find(\"" + radgLineList.ClientID + "\").get_masterTableView();");
                    jscript.Append("grid.rebind();");
                    jscript.Append("}");
                    ScriptManager.RegisterClientScriptBlock(Page, typeof(LineList), "LineListScripts", jscript.ToString(), true);
                }
            }
            private void Refresh()
            {
                if (SearchType == SearchType.QuickSearch)
                    SetupQuickSearch();
                radgLineList.CurrentPageIndex = 0;
                radgLineList.Rebind();
            }

            private void radgLineList_BatchEditCommand(object sender, GridBatchEditingEventArgs e)
            {
            }
            private void GetLastSyncDate()
            {
                lblLastSyncUpdated.Text = LineListEntity.GetLastSyncDate(AssetID);
            }
            #endregion

            protected void btnSync_Click(object sender, EventArgs e)
            {
            }
        }
    }

     

    WEBSERVICE:::::::

    using System; using System.Collections.Generic; using System.ComponentModel; using System.Web.Script.Services; using System.Web.Services; using Shell.SIEP.Common.Helpers; using Telerik.Web.UI; using Shell.SIEP.EDD.BusinessLayer.Mechanical; using System.Data; using Shell.SIEP.EDD.BusinessLayer.Common; namespace EDD.Mechanical.Services {    

     [WebService(Namespace = "http://sww.edd.shell.com/mechanical/AppServices")]     [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]     [ToolboxItem(false)]     [ScriptService]     public class LoadOnDemand : WebService     {         private RadComboBoxItemData[] getDistinctValues(string columnName)         {             string querySql;             querySql = string.Format("Select distinct {0} from V_PIPE_LINELIST order by {0} ", columnName);             DataTable dtResults = new DataTable();             dtResults = Retrieval.RunQueryDT(querySql);             List<RadComboBoxItemData> result = new List<RadComboBoxItemData>(dtResults.Rows.Count);             foreach (DataRow row in dtResults.Rows)             {                 RadComboBoxItemData itemData = new RadComboBoxItemData();                 itemData.Text = row[columnName].ToString();                 itemData.Value = row[columnName].ToString();                 result.Add(itemData);             }             return result.ToArray();         }         [WebMethod]         public RadComboBoxItemData[] LoadVerifiedBy(Dictionary<string, object> context)         {             string columnName = "VERIFIEDBY";             return getDistinctValues(columnName);         }         [WebMethod]         public RadComboBoxItemData[] LoadRevisionName(Dictionary<string, object> context)         {             string columnName = "REVISION_NAME";             return getDistinctValues(columnName);         }

     

     

     

  5. Maria Ilieva
    Admin
    Maria Ilieva avatar
    4017 posts

    Posted 20 Apr Link to this post

    Hi Srikrishna,

    The mentioned issue was a problem in older version of the controls and this behavior is already fixed in the  latest official release. I would suggest you to update your application to the latest version and see how it goes.


    Regards,
    Maria Ilieva
    Telerik
    Do you need help with upgrading your ASP.NET AJAX, WPF or WinForms projects? Check the Telerik API Analyzer and share your thoughts.
  6. Srikrishna
    Srikrishna avatar
    10 posts
    Member since:
    May 2015

    Posted 20 Apr in reply to Maria Ilieva Link to this post

    Hi ,

       Sorry not sure about your reply , as I had the following 3 questions in it.

    Question 1: Is there a way for me to Handle the 'ClearFilter' event in codebehind (or) client side .
    Question 2 : I only want to clear the selected column filter not other remaining columns.
    Question 3 : When I click 'Filter' button - radgrid filters but I don't get to see the loading image. Which shows up on other operations.

     

    You mean to say that Question 2 -- will be resolved with latest version ?

    Can you please suggest something on Question 1 and Question 3?

     

    Thanks

     

  7. Maria Ilieva
    Admin
    Maria Ilieva avatar
    4017 posts

    Posted 25 Apr Link to this post

    Hi Srikrishna,

    1. The ClearFilter method fires OnCommand event and OnUseraction event that can be handeled.
    2. If you need to clear the filter for specific column you could simply filter without parameter to achieve this requirement.
    3. The LoadingPanel will appear when regular Ajax request is performed and when a service is called you should call it manually as shown below:
    http://docs.telerik.com/devtools/aspnet-ajax/controls/ajaxloadingpanel/how-to/show-and-hide-ajaxloadingpanel-explicitly






    Regards,
    Maria Ilieva
    Telerik
    Do you need help with upgrading your ASP.NET AJAX, WPF or WinForms projects? Check the Telerik API Analyzer and share your thoughts.
  8. Srikrishna
    Srikrishna avatar
    10 posts
    Member since:
    May 2015

    Posted 14 Jun in reply to Maria Ilieva Link to this post

    HI MARIA,

       Thank you for the options.

       Could you please give an sample code to using - ' The ClearFilter method fires OnCommand event and OnUseraction event that can be handeled.'

       I have 10 columns in my radgrid , when I click clear filter button --- I don't know how to get the current column & how to uncheck the checkboxs that I selected earlier to filter upon ... I mean I want to perform a nofilter operation on click on clearfilter.

     

       appreciate if you could provide a sample for 1 and 2 options you provided.

    thanks

    krishna

     

  9. Maria Ilieva
    Admin
    Maria Ilieva avatar
    4017 posts

    Posted 17 Jun Link to this post

    Hello,

    You can simply handle the server OnCommand event with Filter command name as when "Clear Filter" button is clicked a filter command with empty filter function, value and expression fires.

    Regards,
    Maria Ilieva
    Telerik
    Do you need help with upgrading your ASP.NET AJAX, WPF or WinForms projects? Check the Telerik API Analyzer and share your thoughts.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017