Hello,
I am having a rad grid, in which I try to filter one column according to a range of dates.
I don't know what is the problem, but the filter is doing its job only by the day of the month.
I will appreciate if you have a look on the following.
Thank you in advance.
Tal
I am having a rad grid, in which I try to filter one column according to a range of dates.
I don't know what is the problem, but the filter is doing its job only by the day of the month.
I will appreciate if you have a look on the following.
Thank you in advance.
Tal
********** aspx:***************
<
telerik:GridBoundColumn
DataField
=
"date"
HeaderText
=
"תאריך"
DataType
=
"System.DateTime"
SortExpression
=
"date"
UniqueName
=
"Date"
DataFormatString
=
"{0:D}"
HeaderStyle-Width
=
"330px"
ItemStyle-HorizontalAlign
=
"Center"
>
<
FilterTemplate
>
מתאריך
<
telerik:RadDatePicker
ID
=
"FromDate"
Culture
=
"he-IL"
runat
=
"server"
Width
=
"140px"
ClientEvents-OnDateSelected
=
"FromDateSelected"
MinDate
=
"07-04-1000"
MaxDate
=
"05-06-3000"
DbSelectedDate='<%# startDate %>'/>
<
dateinput
DateFormat
=
"dd/MM/yyyy"
></
DateInput
>
עד תאריך
<
telerik:RadDatePicker
ID
=
"ToDate"
Culture
=
"he-IL"
runat
=
"server"
Width
=
"140px"
ClientEvents-OnDateSelected
=
"ToDateSelected"
MinDate
=
"07-04-1000"
MaxDate
=
"05-06-3000"
DbSelectedDate='<%# endDate %>'/>
<
dateinput
DateFormat
=
"dd/MM/yyyy"
></
DateInput
>
<
telerik:RadScriptBlock
ID
=
"RadScriptBlock1"
runat
=
"server"
>
<
script
type
=
"text/javascript"
>
function FromDateSelected(sender, args) {
var tableView = $find("<%# ((GridItem)Container).OwnerTableView.ClientID %>");
var ToPicker = $find('<%# ((GridItem)Container).FindControl("ToDate").ClientID %>');
var fromDate = FormatSelectedDate(sender);
var toDate = FormatSelectedDate(ToPicker);
if (toDate != '') {
tableView.filter("Date", fromDate + " " + toDate, "Between");
}
}
function ToDateSelected(sender, args) {
var tableView = $find("<%# ((GridItem)Container).OwnerTableView.ClientID %>");
var FromPicker = $find('<%# ((GridItem)Container).FindControl("FromDate").ClientID %>');
var fromDate = FormatSelectedDate(FromPicker);
var toDate = FormatSelectedDate(sender);
if (fromDate != '')
{
tableView.filter("Date", fromDate + " " + toDate, "Between");
}
}
function FormatSelectedDate(picker) {
var date = picker.get_selectedDate();
var dateInput = picker.get_dateInput();
var formattedDate = dateInput.get_dateFormatInfo().FormatDate(date, dateInput.get_displayDateFormat());
return formattedDate;
}
</
script
>
</
telerik:RadScriptBlock
>
</
FilterTemplate
>
</
telerik:GridBoundColumn
>
code behind cs:
if
(e.CommandName == RadGrid.FilterCommandName)
{
Pair filterPair = (Pair)e.CommandArgument;
switch
(filterPair.Second.ToString())
{
case
"date"
:
this
.startDate = ((e.Item
as
GridFilteringItem)[filterPair.Second.ToString()].FindControl(
"FromDate"
)
as
RadDatePicker).SelectedDate;
this
.endDate = ((e.Item
as
GridFilteringItem)[filterPair.Second.ToString()].FindControl(
"ToDate"
)
as
RadDatePicker).SelectedDate;
break
;
default
:
break
;
}
}