We have a scenario that we have to use RadDataFilter with RadGridView. Now we want to do Sorting and Filtering serverside, But the constraint here is that we have to use only plain WCF Services. No WCF RIA or WCF Data Services.
So problem is how to send filters to server through string.
We found a class to convert filter descriptors to dynamiclinq (string format).
Now the problem with this class is that it always returns string to be empty when we use extension ToDynamicLinq for FilterDescriptors. The commented out method is not compatible with latest release of Silverlight telerik dlls.
Can you please send us a sample project where we can achieve sorting and filtering on server side with RadDataFilter using only Plain WCF Services.
The problem I could see was that in foreach loop, the descriptor are not of type IColumnFilterDescriptor (Check attached image)
rather they are of type Filterdescriptor so extension method taking IColumnFilterDescriptor is not called.
Please check the attached image for clarification.
Thanks and Regards,
Rajat Panwar
So problem is how to send filters to server through string.
We found a class to convert filter descriptors to dynamiclinq (string format).
public
static
class
DescriptorsExtensions
{
public
static
string
ToDynamicLinq(
this
SortDescriptorCollection source)
{
var result =
new
List<
string
>();
foreach
(var d
in
source)
{
if
(d
is
SortDescriptor)
{
result.Add(((SortDescriptor)d).ToDynamicLinq());
}
else
if
(d
is
ColumnSortDescriptor)
{
result.Add(((ColumnSortDescriptor)d).ToDynamicLinq());
}
}
return
String.Join(
","
, result.ToArray());
}
public
static
string
ToDynamicLinq(
this
FilterDescriptorCollection source)
{
var result =
new
List<
string
>();
foreach
(var d
in
source.OfType<IColumnFilterDescriptor>())
{
result.Add(d.ToDynamicLinq());
}
return
String.Join(
" && "
, result.ToArray());
}
public
static
string
ToDynamicLinq(
this
GroupDescriptorCollection source)
{
return
String.Join(
","
, source.OfType<GroupDescriptor>().Select(d => d.Member).ToArray());
}
public
static
string
ToDynamicLinq(
this
SortDescriptor source)
{
return
String.Format(
"{0} {1}"
, source.Member,
source.SortDirection == System.ComponentModel.ListSortDirection.Ascending ?
"asc"
:
"desc"
);
}
public
static
string
ToDynamicLinq(
this
ColumnSortDescriptor source)
{
return
String.Format(
"{0} {1}"
, source.Column.UniqueName,
source.SortDirection == System.ComponentModel.ListSortDirection.Ascending ?
"asc"
:
"desc"
);
}
public
static
string
ToDynamicLinq(
this
GroupDescriptor source)
{
return
String.Format(
"{0} {1}"
, source.Member,
source.SortDirection == System.ComponentModel.ListSortDirection.Ascending ?
"asc"
:
"desc"
);
}
/// <summary>
/// OLD BROKEN
/// </summary>
/// <param name="source"></param>
/// <returns></returns>
//public static string ToDynamicLinq(this ColumnFilterDescriptor source)
//{
// var result = new List<string>();
// foreach (var item in source.DistinctFilter.DistinctValues)
// {
// result.Add(String.Format("{0} == {1}", source.DistinctFilter.Member, item.GetType() == typeof(string) ?
// String.Format(@"""{0}""", item) : item));
// }
// return String.Join(" || ", result.ToArray());
//}
/// <summary>
/// NEW
/// </summary>
/// <param name="source"></param>
/// <returns></returns>
public
static
string
ToDynamicLinq(
this
IColumnFilterDescriptor source)
{
var result =
new
List<
string
>();
foreach
(var item
in
source.DistinctFilter.DistinctValues)
{
result.Add(String.Format(
"{0} == {1}"
, source.Column.UniqueName, item.GetType() ==
typeof
(
string
) ?
String.Format(@
""
"{0}"
""
, item) : item));
}
return
String.Join(
" || "
, result.ToArray());
}
}
Now the problem with this class is that it always returns string to be empty when we use extension ToDynamicLinq for FilterDescriptors. The commented out method is not compatible with latest release of Silverlight telerik dlls.
Can you please send us a sample project where we can achieve sorting and filtering on server side with RadDataFilter using only Plain WCF Services.
The problem I could see was that in foreach loop, the descriptor are not of type IColumnFilterDescriptor (Check attached image)
rather they are of type Filterdescriptor so extension method taking IColumnFilterDescriptor is not called.
Please check the attached image for clarification.
Thanks and Regards,
Rajat Panwar