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

Hide/Show Filtersbycolumn

8 Answers 55 Views
Grid
This is a migrated thread and some comments may be shown as answers.
MikeS
Top achievements
Rank 1
MikeS asked on 22 Mar 2014, 06:38 PM
Hello

I have a radgrid with AllowFilteringByColumn=true and a JS function that hides the filter when the grid is empty:

function Filter(masterTable) {
    var dataItems = masterTable.get_dataItems(); 
    if (dataItems.length == 0) { masterTable.hideFilterItem();  } else { masterTable.showFilterItem(); }
}

however when i perform a search and if that search returns no information, this script also hide the filters, and i dont want to hide after filter is applied(only when grid have no records).

There is a way to know if filters were used? im new to telerik.
Thanks in advance

8 Answers, 1 is accepted

Sort by
0
MikeS
Top achievements
Rank 1
answered on 23 Mar 2014, 06:22 PM
someone? :I
0
MikeS
Top achievements
Rank 1
answered on 23 Mar 2014, 09:38 PM
also i can keep showing the filters when users use the filterbycolumn, if there is a way to know that, but i didnt find any documentation about it.

any help? maybe you guys also have a better idea for this case.

Thanks
0
MikeS
Top achievements
Rank 1
answered on 24 Mar 2014, 05:39 PM
tried to use filterexpressions and use inside if: 

var filterExpressions = masterTable.get_masterTableView().get_filterExpressions();

if (dataItems.length == 0 && filterExpressions.length ) 

but it doesnt work...
0
MikeS
Top achievements
Rank 1
answered on 25 Mar 2014, 05:48 PM
someone please...
0
Eyup
Telerik team
answered on 26 Mar 2014, 03:31 PM
Hello Mike,

Can you please share whether a server-side approach is suitable for you?
protected void RadGrid1_ItemEvent(object sender, GridItemEventArgs e)
{
    if (e.EventInfo is GridInitializePagerItem)
    {
        summarizedCount += (e.EventInfo as GridInitializePagerItem).PagingManager.DataSourceCount;
        e.Item.OwnerTableView.IsFilterItemExpanded = summarizedCount > 0;
    }
}

Looking forward to your reply.

Alternatively, you can use the following property:
<MasterTableView ... ShowHeadersWhenNoRecords="false">

Regards,
Eyup
Telerik
 

Build cross-platform mobile apps using Visual Studio and .NET. Register for the online webinar on 03/27/2014, 11:00AM US ET.. Seats are limited.

 
0
MikeS
Top achievements
Rank 1
answered on 26 Mar 2014, 05:28 PM
hello Eyup. thanks for the reply.

i actually got tired trying a way to do this on client side, so i started working on server side, and i got it working(but not 100% sure)...
after tests i will put here how i did it.

and this:
<MasterTableView ... ShowHeadersWhenNoRecords="false"> 
i have to check if this works... because if it does, i would eat my keyboard eheh

thanks for the reply!
0
MikeS
Top achievements
Rank 1
answered on 26 Mar 2014, 06:27 PM
EDIT:

<MasterTableView ... ShowHeadersWhenNoRecords="false">

this hides everything, i just want the filters.
0
Princy
Top achievements
Rank 2
answered on 27 Mar 2014, 06:05 AM
Hi Mike,

You can try the following code snippet to hide filtering if no records are present before filtering.

C#:
int totalItemCount;
bool isFilter = false;
protected void RadGrid1_ItemEvent(object sender, GridItemEventArgs e)
{
  if (e.EventInfo is GridInitializePagerItem)
  {
    totalItemCount = (e.EventInfo as GridInitializePagerItem).PagingManager.DataSourceCount;
  }
}
protected void RadGrid1_PreRender(object sender, EventArgs e)
{
  Response.Write(totalItemCount);
  if (!isFilter)
  {
    if (totalItemCount <= 0)
    {
     RadGrid1.AllowFilteringByColumn = false;
     RadGrid1.Rebind();
    }      
  }
}
protected void RadGrid1_ItemCommand(object sender, GridCommandEventArgs e)
{
  if (e.CommandName == RadGrid.FilterCommandName)
  {
   isFilter = true;
  }
}

Thanks,
Princy
Tags
Grid
Asked by
MikeS
Top achievements
Rank 1
Answers by
MikeS
Top achievements
Rank 1
Eyup
Telerik team
Princy
Top achievements
Rank 2
Share this question
or