Radgrid multi-filter in sharepoint

3 posts, 0 answers
  1. Ting
    Ting avatar
    2 posts
    Member since:
    Sep 2011

    Posted 23 Jan 2012 Link to this post

    I am facing a wierd issue. I am  currently working on a project which develop usercontrol----> webpart---->deploy to sharepoint. There is one page using  radgrid to display some information which has four filter columns, except the default buildin filter ,I also built my own filter fanction which implement the filter function by hitting the enter key.Everthing is fine when it runs in asp.net ,but when it was deployed to sharepoint site, the filter can work for the first two filters only.In the third filtering,the var grid=$find(gridid) return null. the code  snippet as following:

     

    <script type="text/javascript">
      
      
      
    function doFilter(sender, eventArgs, gridId, uniqueName, curFunction) {
      
    if (eventArgs.keyCode == 13) {
      
    eventArgs.cancelBubble = true;
      
    eventArgs.returnValue = false;
      
    if (eventArgs.stopPropagation) {
      
    eventArgs.stopPropagation();
      
    eventArgs.preventDefault();
      
    }
      
    var masterTableView = $find(gridId).get_masterTableView();
      
    var filterFun;
      
    switch (curFunction) {
      
    case 'Contains':
      
    filterFun = Telerik.Web.UI.GridFilterFunction.Contains;
      
    break;
      
    case 'DoesNotContain':
      
    filterFun = Telerik.Web.UI.GridFilterFunction.DoesNotContain;
      
    break;
      
    case 'StartsWith':
      
    filterFun = Telerik.Web.UI.GridFilterFunction.StartsWith;
      
    break;
      
    case 'EndsWith':
      
    filterFun = Telerik.Web.UI.GridFilterFunction.EndsWith;
      
    break;
      
    case 'EqualTo':
      
    filterFun = Telerik.Web.UI.GridFilterFunction.EqualTo;
      
    break;
      
    case 'NotEqualTo':
      
    filterFun = Telerik.Web.UI.GridFilterFunction.NotEqualTo;
      
    break;
      
    case 'GreaterThan':
      
    filterFun = Telerik.Web.UI.GridFilterFunction.GreaterThan;
      
    break;
      
    case 'LessThan':
      
    filterFun = Telerik.Web.UI.GridFilterFunction.LessThan;
      
    break;
      
    case 'GreaterThanOrEqualTo':
      
    filterFun = Telerik.Web.UI.GridFilterFunction.GreaterThanOrEqualTo;
      
    break;
      
    case 'LessThanOrEqualTo':
      
    filterFun = Telerik.Web.UI.GridFilterFunction.LessThanOrEqualTo;
      
    break;
      
    case 'Between':
      
    filterFun = Telerik.Web.UI.GridFilterFunction.Between;
      
    break;
      
    case 'NotBetween':
      
    filterFun = Telerik.Web.UI.GridFilterFunction.NotBetween;
      
    break;
      
    case 'IsEmpty':
      
    filterFun = Telerik.Web.UI.GridFilterFunction.IsEmpty;
      
    break;
      
    case 'NotIsEmpty':
      
    filterFun = Telerik.Web.UI.GridFilterFunction.NotIsEmpty;
      
    break;
      
    case 'IsNull':
      
    filterFun = Telerik.Web.UI.GridFilterFunction.IsNull;
      
    break;
      
    case 'NotIsNull':
      
    filterFun = Telerik.Web.UI.GridFilterFunction.NotIsNull;
      
    break;
      
    default:
      
    filterFun = Telerik.Web.UI.GridFilterFunction.EqualTo;
      
    }
      
    if (sender.value == "")
      
    filterFun = Telerik.Web.UI.GridFilterFunction.NoFilter;
      
    if (masterTableView !=null)
      
    masterTableView.filter(uniqueName, sender.value, filterFun);
      
    return false;
      
    }
      
    }
      
      
      
    </script>
      
      
      
      
    <telerik:RadGrid ID="RGrid_LocateAsset" runat="server" AutoGenerateColumns="False"
      
    GridLines="None" AllowFilteringByColumn="True" AllowSorting="True" Skin="Sunset"
      
    AllowPaging="True" EnableViewState="true" OnNeedDataSource="RGridNeedDataSource">
      
    <GroupingSettings CaseSensitive="False" />
      
    <MasterTableView EnableColumnsViewState="true">
      
    <CommandItemSettings ExportToPdfText="Export to Pdf"></CommandItemSettings>
      
    <RowIndicatorColumn FilterControlAltText="Filter RowIndicator column">
      
    <HeaderStyle Width="20px"></HeaderStyle>
      
    </RowIndicatorColumn>
      
    <ExpandCollapseColumn FilterControlAltText="Filter ExpandColumn column">
      
    <HeaderStyle Width="20px"></HeaderStyle>
      
    </ExpandCollapseColumn>
      
    <Columns>
      
    <telerik:GridBoundColumn AllowFiltering="False" DataField="MakeModelName" FilterControlAltText="Filter column column"
      
    HeaderText="Model" UniqueName="MakeModelName" HeaderStyle-Width="75px">
      
    </telerik:GridBoundColumn>
      
    <telerik:GridBoundColumn AllowFiltering="False" DataField="AssetInstanceSerial" FilterControlAltText="Filter column1 column"
      
    HeaderText="Serial #" UniqueName="AssetInstanceSerial" HeaderStyle-Width="75px">
      
    </telerik:GridBoundColumn>
      
    <telerik:GridBoundColumn AllowFiltering="False" DataField="UDI" FilterControlAltText="Filter column2 column"
      
    HeaderText="UDI" UniqueName="UDI">
      
    </telerik:GridBoundColumn>
      
    <telerik:GridBoundColumn AllowFiltering="False" DataField="RFIDTagNumber" FilterControlAltText="Filter column7 column"
      
    HeaderText="RFID Tag#" UniqueName="RfidTagNumber" HeaderStyle-Width="75px">
      
    </telerik:GridBoundColumn>
      
    <telerik:GridTemplateColumn FilterControlAltText="Filter TemplateColumn3 column"
      
    DataField="AssetStatus" CurrentFilterFunction="EqualTo" HeaderText="Status" UniqueName="statusname">
      
    <ItemTemplate>
      
    <div id="GridColumn">
      
    <%# (string.IsNullOrEmpty(Eval("AssetStatus").ToString()) ? "Asset Status not available" : Eval("AssetStatus"))%>
      
    </div>
      
    </ItemTemplate>
      
    </telerik:GridTemplateColumn>
      
    <telerik:GridTemplateColumn FilterControlAltText="Filter TemplateColumn2 column"
      
    DataField="floorname" CurrentFilterFunction="EqualTo" HeaderText="Floor" UniqueName="FloorName">
      
    <ItemTemplate>
      
    <div id="GridColumn">
      
    <%# (string.IsNullOrEmpty(Eval("FloorName").ToString()) ? "Location not available" : Eval("FloorName"))%>
      
    </div>
      
    </ItemTemplate>
      
    </telerik:GridTemplateColumn>
      
    <telerik:GridTemplateColumn FilterControlAltText="Filter TemplateColumn column" HeaderText="Unit"
      
    DataField="UnitName" CurrentFilterFunction="EqualTo" UniqueName="UnitName">
      
    <ItemTemplate>
      
    <div id="GridColumn">
      
    <%# (string.IsNullOrEmpty(Eval("UnitName").ToString()) ? "Location not available" : String.Format(@"<a href='" + FloorPlanURL + "?TagID={0}&HospitalSite={1}&selectedAssetKeys={3}' >{2}</a>", Eval("RFIDTagNumber").ToString(), Eval("HospitalGlnId").ToString(), Eval("UnitName").ToString(), AssetIDS))%>
      
      
    </div>
      
    </ItemTemplate>
      
    </telerik:GridTemplateColumn>
      
    <telerik:GridTemplateColumn FilterControlAltText="Filter TemplateColumn1 column"
      
    DataField="RoomName" CurrentFilterFunction="EqualTo" HeaderText="Room" UniqueName="RoomName">
      
    <ItemTemplate>
      
    <div id="GridColumn">
      
    <%# (string.IsNullOrEmpty(Eval("RoomName").ToString()) ? "Location not available" : Eval("RoomName"))%>
      
    </div>
      
    </ItemTemplate>
      
    </telerik:GridTemplateColumn>
      
    </Columns>
      
    <EditFormSettings>
      
    <EditColumn FilterControlAltText="Filter EditCommandColumn column">
      
    </EditColumn>
      
    </EditFormSettings>
      
    </MasterTableView>
      
    <FilterMenu EnableImageSprites="False">
      
    </FilterMenu>
      
    <HeaderContextMenu CssClass="GridContextMenu GridContextMenu_Default">
      
    </HeaderContextMenu>
      
    </telerik:RadGrid>
      
      
    //code behide
      
      
    protected void RGridNeedDataSource(object source, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
      
    {
      
      
    GetURLParamete();
      
      
    string currentHospitalGLNID = GetPersistedObject(PersistentObjectType.HospitalGLNID).ToString();
      
    EntityCollection<AssetLocationViewEntity> assetLocationView= LocateAssetPresenter.GetAllAssetLocation(currentHospitalGLNID, assetIDs, filterName, filterValue);
      
    RGrid_LocateAsset.DataSource = assetLocationView;
      
    RGrid_LocateAsset.ItemCreated += new GridItemEventHandler(RGrid_LocateAsset_ItemCreated);
      
      
    }
      
      
    protected void RGrid_LocateAsset_ItemCreated(object sender, GridItemEventArgs e)
      
    {
      
    if (e.Item is GridFilteringItem)
      
    {
      
    GridFilteringItem fltItem = e.Item as GridFilteringItem;
      
    foreach (GridColumn column in RGrid_LocateAsset.Columns)
      
    {
      
    //Filter out non-data or non-filter columns
      
      
    if (column.ColumnType == "GridTemplateColumn")
      
    {
      
    GridTemplateColumn bndcol = (GridTemplateColumn)column;
      
    if (bndcol.AllowFiltering == true)
      
    {
      
      
    TextBox txtbox = fltItem[column.UniqueName].Controls[0] as TextBox;
      
    var currentFilter = column.CurrentFilterFunction;
      
    if (txtbox != null)
      
    txtbox.Attributes.Add("onkeydown", String.Format("doFilter(this, event, \"{0}\", \"{1}\", \"{2}\");", RGrid_LocateAsset.ClientID, column.UniqueName, currentFilter));
      
    }
      
    }
      
    }
      
    }
      
    }

     

     

  2. Ting
    Ting avatar
    2 posts
    Member since:
    Sep 2011

    Posted 25 Jan 2012 Link to this post

    I took off my own javascript function ,use its own filter function, same problem happened

  3. Marin
    Admin
    Marin avatar
    1044 posts

    Posted 26 Jan 2012 Link to this post

    Hi Ting,

     It the code that you have posted you attach and event handler for the ItemCreated event from the NeedDataSource event of the grid. This might be too late in the page life cycle. You should attach event handlers either on OnInit from code behind or in the markup for the grid. Also you should check with what arguments the function is called and whether they are passed correctly from code behind. Also if you use any ajax on the page try turning it off to see if this causes the problem.

    Kind regards,
    Marin
    the Telerik team
    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 their blog feed now
Back to Top