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

Remove GridDateTimeColumn DateRange filter when both date pickers are blank

5 Answers 36 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Guillermo
Top achievements
Rank 1
Guillermo asked on 19 Aug 2015, 06:59 PM

Hello, I'm trying to do something pretty straightforward, I'd like to remove the filter parameters from my grid results when clearing the two datepickers from the griddatetime column daterange filter. Example (From: 01/01/2015 To: 02/01/2015....results in data between that date range, If I were to clear the two datepickers, the grid does not return ALL records nor does it even do a postback like any other filter types that get cleared.

 

Here is my markup.

<telerik:GridDateTimeColumn DataField="AssignedDate" DataType="System.DateTime"   DataFormatString="{0:d}" FilterControlAltText="Filter AssignedDate column" HeaderText="Assigned Date" SortExpression="AssignedDate" EnableRangeFiltering="true" PickerType="DatePicker" UniqueName="AssignedDate" ShowFilterIcon="false" AutoPostBackOnFilter="true" >
 <HeaderStyle  HorizontalAlign="Center" Width="300px" />
<ItemStyle   HorizontalAlign="Center" />
</telerik:GridDateTimeColumn>

5 Answers, 1 is accepted

Sort by
0
Eyup
Telerik team
answered on 24 Aug 2015, 08:16 AM
Hello Guillermo,

I've already replied to your query in your formal support ticket with ID:964007. I suggest that we continue our conversation on the mentioned thread.

Regards,
Eyup
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Guillermo
Top achievements
Rank 1
answered on 24 Aug 2015, 01:24 PM

Thank you Eyup for your reply and the posted solution. I was able to find something very similar in that you would need to add a clear button to clear the filters however, for the purpose of consistency, I'd like to see how we could clear the filter automatically when both date pickers get cleared. I'll be waiting for your reply.

Thanks and regards,

Guillermo

0
Eyup
Telerik team
answered on 27 Aug 2015, 07:44 AM
Hi Guillermo,

I believe the matter is resolved in the mentioned support ticket thread. If new questions arise, I suggest that you post them there.

Regards,
Eyup
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Hassan
Top achievements
Rank 1
answered on 14 Aug 2019, 08:54 AM

Hello Eyups,

I would like to see the solution ,please

0
Eyup
Telerik team
answered on 19 Aug 2019, 07:09 AM
Hi Hassan,

I am sending the sample with this post. I hope it might prove helpful to other developers as well

If you'd like to see how to clear the filter automatically when both date pickers get cleared, you can check this modification:
protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e)
{
    if (e.Item is GridFilteringItem)
    {
        GridFilteringItem filterItem = e.Item as GridFilteringItem;
        var columns = filterItem.OwnerTableView.RenderColumns
            .OfType<GridDateTimeColumn>()
            .Where(x => x.AllowFiltering && x.EnableRangeFiltering);
  
        foreach (GridColumn col in columns)
        {
            RadDatePicker picker = filterItem[col.UniqueName].Controls[1] as RadDatePicker;
            picker.ClientEvents.OnDateSelected = "clearIfEmpty";
  
            picker = filterItem[col.UniqueName].Controls[4] as RadDatePicker;
            picker.ClientEvents.OnDateSelected = "clearIfEmpty";
        }
    }
}

JavaScript:
function clearIfEmpty(sender, args) {
    var isEmpty = true;
    var cell = $(sender.get_element()).closest("td");
    cell.find(".RadPicker")
        .each(function (i, e) {
            var pickerID = e.id.replace("_wrapper", "");
            var picker = $find(pickerID);
            if (picker.get_selectedDate()) {
                isEmpty = false;
            }
        });
    if (isEmpty) {
        var tableView = sender.get_parent();
        var colName = tableView.get_columns()[cell.index()].get_uniqueName();
        tableView.filter(colName, "", "NoFilter");
    }
}

I hope this will prove helpful.

Regards,
Eyup
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
Grid
Asked by
Guillermo
Top achievements
Rank 1
Answers by
Eyup
Telerik team
Guillermo
Top achievements
Rank 1
Hassan
Top achievements
Rank 1
Share this question
or