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
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

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
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

Hello Eyups,
I would like to see the solution ,please
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