In my example there a record in 2nd page "'Common name" column "Marsh Marigold".from first page I search for this record
my search conditions are
1. Mar->yes
2 .mar->no
3 gold->No
I am trying to do filter for all above mentioned case but only for 1st case data filter and display in grid.I post sample test case bellow.
MODEL
public class remotefilterpaging
{
public class Plant
{
public string Common
{
get;
set;
}
public string Botanical
{
get;
set;
}
public static Paging<Plant> PlantsPaging(StoreRequestParameters parameters, string filterheader)
{
var data = Plant.GetPlants();
return Plant.PlantsPaging(parameters.Start, parameters.Limit, parameters.SimpleSort, parameters.SimpleSortDirection, filterheader);
}
public static Paging<Plant> PlantsPaging(int start, int limit, string sort, SortDirection dir, string filter)
{
List<Plant> plants = Plant.GetPlants();
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 = plants.Count > 0 && plants[0].GetType().GetProperty(dataIndex).PropertyType == typeof(int);
switch (condition.Operator)
{
case "=":
if (isInt)
{
value = condition.Value<int>();
}
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();
}
plants.RemoveAll(item =>
{
object oValue = item.GetType().GetProperty(dataIndex).GetValue(item, null);
string matchValue = null;
string itemValue = null;
if (type == FilterType.String)
{
matchValue = (string)value;
itemValue = oValue as string;
}
switch (op)
{
case "=":
return oValue == null || !oValue.Equals(value);
case "compare":
return !((IEquatable<IComparable>)value).Equals((IComparable)oValue);
case "+":
return itemValue == null || !itemValue.StartsWith(matchValue);
case "-":
return itemValue == null || !itemValue.EndsWith(matchValue);
case "!":
return itemValue == null || itemValue.IndexOf(matchValue) >= 0;
case "*":
return itemValue == null || itemValue.IndexOf(matchValue) < 0;
default:
throw new Exception("Not supported operator");
}
});
}
//-- end filtering ------------------------------------------------------------
if ((start + limit) > plants.Count)
{
limit = plants.Count - start;
}
List<Plant> rangePlants = (start < 0 || limit < 0) ? plants : plants.GetRange(start, limit);
return new Paging<Plant>(rangePlants, plants.Count);
}
public static List<Plant> GetPlants()
{
return new List<Plant> {
new Plant
{
Common = "Bloodroot",
Botanical = "Sanguinaria canadensis",
},
new Plant
{
Common = "Columbine",
Botanical = "Aquilegia canadensis",
},
new Plant
{
Common = "Marsh Marigold",
Botanical = "Caltha palustris",
},
new Plant
{
Common = "Cowslip",
Botanical = "Caltha palustris",
},
};
}
}
}
View
@using Ext.Net;
@using Ext.Net.MVC;
@{
var X = Html.X();
Layout = null;
}
<!DOCTYPE html>
<html>
<head>
<script>
Ext.net.FilterHeader.behaviour.string[0].match = function (recordValue, matchValue) {
return (Ext.net.FilterHeader.behaviour.getStrValue(recordValue) || "").indexOf(matchValue) > -1;
}
</script>
<meta name="viewport" content="width=device-width" />
<title>Index</title>
</head>
<body>
<div>
@X.ResourceManager()
@(
Html.X().GridPanel()
.Title("Plants")
.Frame(true)
.Height(300)
.Store(
Html.X().Store()
.RemoteFilter(true)
.Proxy(Html.X().AjaxProxy()
.Url(Url.Action("Read"))
.Reader(Html.X().JsonReader().Root("data"))
)
.PageSize(2)
.Model
(
X.Model()
.Fields
(
X.ModelField().Name("Common").Type(ModelFieldType.String),
X.ModelField().Name("Botanical").Type(ModelFieldType.String)
)
)
)
.ColumnModel(
Html.X().Column().DataIndex("Common").Text("Common Name").Flex(1),
Html.X().Column().DataIndex("Botanical").Text("Botanical").Width(230)
)
.Plugins
(
Html.X().FilterHeader().Remote(true)
)
.BottomBar(
Html.X().PagingToolbar()
.DisplayInfo(true)
.DisplayMsg("Displaying plants {0} - {1} of {2}")
.EmptyMsg("No plants to display")
)
)
</div>
</body>
</html>
CONTROLLER
public ActionResult Index()
{
return View();
}
public ActionResult Read(StoreRequestParameters parameters, string filterheader)
{
return this.Store(remotefilterpaging.Plant.PlantsPaging(parameters, filterheader));
}
please investigate.