PDA

View Full Version : [CLOSED] FilterHeader plugin : override Operator of Parameters["filterheader"]



matrixwebtech
Apr 16, 2015, 6:39 PM
In example (http://examples2.ext.net/#/GridPanel/FilterHeader/Remote/) Operator automatically set for different data type ,but what if I want to change may be I want to pass * for all data types .

Daniil
Apr 16, 2015, 9:27 PM
Hi @matrixwebtech,

Yes, the * operator is available for strings only.

This example demonstrates how to define a custom operator.
http://examples2.ext.net/#/GridPanel/FilterHeader/Custom_Behaviour

Here you can investigate how the * operator is defined for strings. Please search for op: "*":
http://svn.ext.net/premium/trunk/Ext.Net/Build/Ext.Net/ux/filterheader/filterheader-debug.js

matrixwebtech
Apr 17, 2015, 3:15 AM
Hi Daniil
Thakns for reply,I will study your suggestion today but yesterday before post I do this with server side code and working as I want please check and tell me this approach is correct or not .


public Paging<object> RemotePagingAndFilter(int start, int limit, string sort, SortDirection dir, string filter)
{

var data = this.GetData();


FilterHeaderConditions fhc = new FilterHeaderConditions(filter);

foreach (FilterHeaderCondition condition in fhc.Conditions)
{
string dataIndex = condition.DataIndex;
FilterType type = condition.Type;
string op = condition.Operator;
object value = null;

switch (condition.Type)
{
case FilterType.Boolean:
value = condition.Value<bool>();
break;

case FilterType.Date:
switch (condition.Operator)
{
case "=":
value = condition.Value<DateTime>();
break;

case "compare":
value = FilterHeaderComparator<DateTime>.Parse(condition.JsonValue);
break;
}
break;

case FilterType.Numeric:
bool isInt = data.Count > 0 && data[0].GetType().GetProperty(dataIndex).PropertyType == typeof(int);
bool isInt64 = data.Count > 0 && data[0].GetType().GetProperty(dataIndex).PropertyType == typeof(Int64);
switch (condition.Operator)
{
case "=":
if (isInt)
{
value = condition.Value<int>();
}
else if(isInt64)
{
value = condition.Value<Int64>();
}
else
{
value = condition.Value<double>();
}
break;

case "compare":
if (isInt)
{
value = FilterHeaderComparator<int>.Parse(condition.JsonValue);
}
else
{
value = FilterHeaderComparator<double>.Parse(condition.JsonValue);
}

break;
}

break;
case FilterType.String:
value = condition.Value<string>();
break;
default:
throw new ArgumentOutOfRangeException();
}

data.RemoveAll(item =>
{
object oValue = item.GetType().GetProperty(dataIndex).GetValue(ite m, null);
string matchValue = null;
string itemValue = null;

if (type == FilterType.String)
{
matchValue = (string)value.ToString().ToLower();
itemValue = oValue.ToString().ToLower() as string;
}

if(type==FilterType.Numeric)
{
matchValue = (string)value.ToString().ToLower();
itemValue =Convert.ToString(oValue);
}
switch (type)
{
case FilterType.String:
return itemValue == null || itemValue.IndexOf(matchValue) < 0;

case FilterType.Numeric:

return itemValue == null || !itemValue.StartsWith(matchValue);
default:
throw new Exception("Not supported operator");
}


});
}
//-- end filtering ------------------------------------------------------------




if ((start + limit) > data.Count)
{
limit = data.Count - start;
}

List<tbl_SysMenuMaster> rangePlants = (start < 0 || limit < 0) ? data : data.GetRange(start, limit);

return new Paging<object>(rangePlants, data.Count);
}

Daniil
Apr 17, 2015, 1:55 PM
At the first glance I don't see anything wrong in your solution. If it works as you need, it is definitely a way to go.