PDA

View Full Version : [CLOSED] Example need for remote paging and filterheader



matrixwebtech
Aug 11, 2014, 4:11 AM
hi
I want to create a grid panel with remote paging and remote filter in MVC Razor. I want filter in every column in gridpanel.please give some example in MVC with Razor syntax.

I need http://examples2.ext.net/#/GridPanel/FilterHeader/Remote/ in MVC Razor syntax.

geoffrey.mcgill
Aug 11, 2014, 7:08 AM
Please feel free to convert as much of the WebForm sample as possible and post here in the forums to share with others.

If you run into a specific issues, please post the simplified sample demonstrating the scenario and we can help debug.

matrixwebtech
Aug 11, 2014, 8:29 AM
I follow http://mvc.ext.net/#/GridPanel_Paging_and_Sorting/Remote/

And prepare a test case.but I will not figure out how to implement remote filter.I found here(http://examples2.ext.net/#/GridPanel/FilterHeader/Remote/)

StoreReadDataEventArgs e and

FilterHeaderConditions fhc = new FilterHeaderConditions(e.Parameters["filterheader"]);

I will not able to implement above things




VIEW




@{
var X = Html.X();
Layout = null;
}

<!DOCTYPE html>

<html>
<head>
<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"))

//.ActionMethods(actions => {
// actions.Read = HttpMethod.POST;
// })
)
//.RemoteSort(true)
.PageSize(5)
.Model
(
X.Model()
.Fields
(
X.ModelField().Name("Common").Type(ModelFieldType.String),
X.ModelField().Name("Botanical").Type(ModelFieldType.String),
X.ModelField().Name("Light").Type(ModelFieldType.String),
X.ModelField().Name("Price").Type(ModelFieldType.Float),
X.ModelField().Name("Availability").Type(ModelFieldType.Date),
X.ModelField().Name("Indoor").Type(ModelFieldType.Boolean)
)

)
)
.ColumnModel(
Html.X().Column().DataIndex("Common").Text("Common Name").Flex(1),
Html.X().Column().DataIndex("Botanical").Text("Botanical").Width(230),
Html.X().Column().DataIndex("Light").Text("Light").Width(130),
Html.X().Column().DataIndex("Price").Text("Price").Width(70).Align(Alignment.Right),
Html.X().DateColumn().DataIndex("Availability").Text("Available").Width(95).Format("yyyy-MM-dd"),
Html.X().Column().DataIndex("Indoor").Text("Indoor?").Width(55)

)
.Plugins
(
Html.X().FilterHeader().Remote(true)//.FilterParam("filterheader")

)

.BottomBar(
Html.X().PagingToolbar()
.DisplayInfo(true)
.DisplayMsg("Displaying plants {0} - {1} of {2}")
.EmptyMsg("No plants to display")
)
)

</div>
</body>
</html>


MODEL


using Ext.Net;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Ext.Net.MVC;

namespace e.Models
{
public class remotefilterpaging
{

public class Plant
{
public string Common
{
get;
set;
}

public string Botanical
{
get;
set;
}

public string Zone
{
get;
set;
}

public string ColorCode
{
get;
set;
}

public string Light
{
get;
set;
}

public double Price
{
get;
set;
}

public DateTime Availability
{
get;
set;
}

public bool Indoor
{
get;
set;
}

public static Paging<Plant> PlantsPaging(StoreRequestParameters parameters, string filterheader)
{
var data = Plant.GetPlants();

FilterHeaderConditions fhc = new FilterHeaderConditions(filterheader);

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);
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();
}

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

return Plant.PlantsPaging(parameters.Start, parameters.Limit, parameters.SimpleSort, parameters.SimpleSortDirection, null);
}

public static Paging<Plant> PlantsPaging(int start, int limit, string sort, SortDirection dir, string filter)
{
List<Plant> plants = Plant.GetPlants();

if (!string.IsNullOrEmpty(filter) && filter != "*")
{
plants.RemoveAll(plant => !plant.Common.ToLower().StartsWith(filter.ToLower( )));
}

if (!string.IsNullOrEmpty(sort))
{
plants.Sort(delegate(Plant x, Plant y)
{
object a;
object b;

int direction = dir == SortDirection.DESC ? -1 : 1;

a = x.GetType().GetProperty(sort).GetValue(x, null);
b = y.GetType().GetProperty(sort).GetValue(y, null);

return CaseInsensitiveComparer.Default.Compare(a, b) * direction;
});
}

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",
Zone = "4",
ColorCode = "E7E7E7",
Light = "Mostly Shady",
Price = 2.44,
Availability = new DateTime(2006, 03, 15),
Indoor = true
},

new Plant
{
Common = "Columbine",
Botanical = "Aquilegia canadensis",
Zone = "3",
ColorCode = "E7E7E7",
Light = "Mostly Shady",
Price = 9.37,
Availability = new DateTime(2006, 03, 06),
Indoor = true
},

new Plant
{
Common = "Marsh Marigold",
Botanical = "Caltha palustris",
Zone = "4",
ColorCode = "F5F5F5",
Light = "Mostly Sunny",
Price = 6.81,
Availability = new DateTime(2006, 05, 17),
Indoor = false
},

new Plant
{
Common = "Cowslip",
Botanical = "Caltha palustris",
Zone = "4",
ColorCode = "E7E7E7",
Light = "Mostly Shady",
Price = 9.90,
Availability = new DateTime(2006, 03, 06),
Indoor = true
},

new Plant
{
Common = "Dutchman's-Breeches",
Botanical = "Dicentra cucullaria",
Zone = "3",
ColorCode = "E7E7E7",
Light = "Mostly Shady",
Price = 6.44,
Availability = new DateTime(2006, 01, 20),
Indoor = true
},

new Plant
{
Common = "Ginger, Wild",
Botanical = "Asarum canadense",
Zone = "3",
ColorCode = "E7E7E7",
Light = "Mostly Shady",
Price = 9.03,
Availability = new DateTime(2006, 04, 18),
Indoor = true
},

new Plant
{
Common = "Hepatica",
Botanical = "Hepatica americana",
Zone = "4",
ColorCode = "E7E7E7",
Light = "Mostly Shady",
Price = 4.45,
Availability = new DateTime(2006, 01, 26),
Indoor = true
},

new Plant
{
Common = "Liverleaf",
Botanical = "Hepatica americana",
Zone = "4",
ColorCode = "E7E7E7",
Light = "Mostly Shady",
Price = 3.99,
Availability = new DateTime(2006, 01, 02),
Indoor = true
},

new Plant
{
Common = "Jack-In-The-Pulpit",
Botanical = "Arisaema triphyllum",
Zone = "4",
ColorCode = "E7E7E7",
Light = "Mostly Shady",
Price = 3.23,
Availability = new DateTime(2006, 02, 01),
Indoor = true
},

new Plant
{
Common = "Mayapple",
Botanical = "Podophyllum peltatum",
Zone = "3",
ColorCode = "E7E7E7",
Light = "Mostly Shady",
Price = 2.98,
Availability = new DateTime(2006, 06, 05),
Indoor = true
},

new Plant
{
Common = "Phlox, Woodland",
Botanical = "Phlox divaricata",
Zone = "3",
ColorCode = "EEEEEE",
Light = "Sun or Shade",
Price = 2.80,
Availability = new DateTime(2006, 01, 22),
Indoor = false
},

new Plant
{
Common = "Phlox, Blue",
Botanical = "Phlox divaricata",
Zone = "3",
ColorCode = "EEEEEE",
Light = "Sun or Shade",
Price = 5.59,
Availability = new DateTime(2006, 02, 16),
Indoor = false
},

new Plant
{
Common = "Spring-Beauty",
Botanical = "Claytonia Virginica",
Zone = "7",
ColorCode = "E7E7E7",
Light = "Mostly Shady",
Price = 6.59,
Availability = new DateTime(2006, 02, 01),
Indoor = true
},

new Plant
{
Common = "Trillium",
Botanical = "Trillium grandiflorum",
Zone = "5",
ColorCode = "EEEEEE",
Light = "Sun or Shade",
Price = 3.90,
Availability = new DateTime(2006, 04, 29),
Indoor = false
},

new Plant
{
Common = "Wake Robin",
Botanical = "Trillium grandiflorum",
Zone = "5",
ColorCode = "EEEEEE",
Light = "Sun or Shade",
Price = 3.20,
Availability = new DateTime(2006, 02, 21),
Indoor = false
},

new Plant
{
Common = "Violet, Dog-Tooth",
Botanical = "Erythronium americanum",
Zone = "4",
ColorCode = "E1E1E1",
Light = "Shade",
Price = 9.04,
Availability = new DateTime(2006, 02, 01),
Indoor = true
},

new Plant
{
Common = "Trout Lily",
Botanical = "Erythronium americanum",
Zone = "4",
ColorCode = "E1E1E1",
Light = "Shade",
Price = 6.94,
Availability = new DateTime(2006, 03, 24),
Indoor = true
},

new Plant
{
Common = "Adder's-Tongue",
Botanical = "Erythronium americanum",
Zone = "4",
ColorCode = "E1E1E1",
Light = "Shade",
Price = 9.58,
Availability = new DateTime(2006, 04, 13),
Indoor = true
},

new Plant
{
Common = "Anemone",
Botanical = "Anemone blanda",
Zone = "6",
ColorCode = "E7E7E7",
Light = "Mostly Shady",
Price = 8.86,
Availability = new DateTime(2006, 12, 26),
Indoor = true
},

new Plant
{
Common = "Grecian Windflower",
Botanical = "Anemone blanda",
Zone = "6",
ColorCode = "E7E7E7",
Light = "Mostly Shady",
Price = 9.16,
Availability = new DateTime(2006, 07, 10),
Indoor = true
},

new Plant
{
Common = "Bee Balm",
Botanical = "Monarda didyma",
Zone = "4",
ColorCode = "E1E1E1",
Light = "Shade",
Price = 4.59,
Availability = new DateTime(2006, 05, 03),
Indoor = true
},

new Plant
{
Common = "Bergamot",
Botanical = "Monarda didyma",
Zone = "4",
ColorCode = "E1E1E1",
Light = "Shade",
Price = 7.16,
Availability = new DateTime(2006, 04, 27),
Indoor = true
},

new Plant
{
Common = "Black-Eyed Susan",
Botanical = "Rudbeckia hirta",
Zone = "Annual",
ColorCode = "FFFFFF",
Light = "Sunny",
Price = 9.80,
Availability = new DateTime(2006, 06, 18),
Indoor = false
},

new Plant
{
Common = "Buttercup",
Botanical = "Ranunculus",
Zone = "4",
ColorCode = "E1E1E1",
Light = "Shade",
Price = 2.57,
Availability = new DateTime(2006, 06, 10),
Indoor = true
},

new Plant
{
Common = "Crowfoot",
Botanical = "Ranunculus",
Zone = "4",
ColorCode = "E1E1E1",
Light = "Shade",
Price = 9.34,
Availability = new DateTime(2006, 04, 03),
Indoor = true
},

new Plant
{
Common = "Butterfly Weed",
Botanical = "Asclepias tuberosa",
Zone = "Annual",
ColorCode = "FFFFFF",
Light = "Sunny",
Price = 2.78,
Availability = new DateTime(2006, 06, 30),
Indoor = false
},

new Plant
{
Common = "Cinquefoil",
Botanical = "Potentilla",
Zone = "Annual",
ColorCode = "E1E1E1",
Light = "Shade",
Price = 7.06,
Availability = new DateTime(2006, 05, 25),
Indoor = true
},

new Plant
{
Common = "Primrose",
Botanical = "Oenothera",
Zone = "3 - 5",
ColorCode = "FFFFFF",
Light = "Sunny",
Price = 6.56,
Availability = new DateTime(2006, 01, 30),
Indoor = false
},

new Plant
{
Common = "Gentian",
Botanical = "Gentiana",
Zone = "4",
ColorCode = "EEEEEE",
Light = "Sun or Shade",
Price = 7.81,
Availability = new DateTime(2006, 05, 18),
Indoor = false
},

new Plant
{
Common = "Blue Gentian",
Botanical = "Gentiana",
Zone = "4",
ColorCode = "EEEEEE",
Light = "Sun or Shade",
Price = 8.56,
Availability = new DateTime(2006, 05, 02),
Indoor = false
},

new Plant
{
Common = "Jacob's Ladder",
Botanical = "Polemonium caeruleum",
Zone = "Annual",
ColorCode = "E1E1E1",
Light = "Shade",
Price = 9.26,
Availability = new DateTime(2006, 02, 21),
Indoor = true
},

new Plant
{
Common = "Greek Valerian",
Botanical = "Polemonium caeruleum",
Zone = "Annual",
ColorCode = "E1E1E1",
Light = "Shade",
Price = 4.36,
Availability = new DateTime(2006, 07, 14),
Indoor = true
},

new Plant
{
Common = "California Poppy",
Botanical = "Eschscholzia californica",
Zone = "Annual",
ColorCode = "FFFFFF",
Light = "Sunny",
Price = 7.89,
Availability = new DateTime(2006, 03, 27),
Indoor = false
},

new Plant
{
Common = "Shooting Star",
Botanical = "Dodecatheon",
Zone = "Annual",
ColorCode = "E7E7E7",
Light = "Mostly Shady",
Price = 8.60,
Availability = new DateTime(2006, 05, 13),
Indoor = true
},

new Plant
{
Common = "Snakeroot",
Botanical = "Cimicifuga",
Zone = "Annual",
ColorCode = "E1E1E1",
Light = "Shade",
Price = 5.63,
Availability = new DateTime(2006, 07, 11),
Indoor = true
},

new Plant
{
Common = "Cardinal Flower",
Botanical = "Lobelia cardinalis",
Zone = "2",
ColorCode = "E1E1E1",
Light = "Shade",
Price = 3.02,
Availability = new DateTime(2006, 02, 22),
Indoor = true
}
};
}
}
}
}


CONTROLLER


using Ext.Net;
using Ext.Net.MVC;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using e.Models;

namespace e.Controllers
{
public class remotefilterpagingController : Controller
{
//
// GET: /remotefilterpaging/

public ActionResult Index()
{
return View();
}

public ActionResult Read(StoreRequestParameters parameters, string filterheader)
{
return this.Store(remotefilterpaging.Plant.PlantsPaging(p arameters,filterheader));
}

}
}

Daniil
Aug 11, 2014, 1:20 PM
As for a StoreReadDataEventArgs.

It is used in a conjunction with a PageProxy and that approach is not actual for MVC. Please use an AjaxProxy.

As for a FilterHeaderConditions.

You can take a "filterheader" directly from a Request

Request["filterheader"]
or try to define it in an action's signature:

public ActionResult Read(StoreRequestParameters parameters, string filterheader)

matrixwebtech
Aug 11, 2014, 2:17 PM
I change my code at http://forums.ext.net/showthread.php?41301-Example-need-for-remote-paging-and-filterheader&p=186921#post186921.
But filtering not done,I use AjaxProxy as per your suggestion.can you please check.

I search for May on first page but no filtering done.

what is op in filterheader?can you please give me more details on filterheader

Daniil
Aug 11, 2014, 3:30 PM
But filtering not done

Why? Is the "filterheader" variable empty in a controller action or does it contain applied filters?


what is op in filterheader?

Where is it?

matrixwebtech
Aug 11, 2014, 3:47 PM
Is my code is right?
"filterheader" variable contains every thing but Remote filtering not working.

as I said,
I search for May on first page "Common Name" column and "Mayapple" present in 2nd page but no filtering done.

geoffrey.mcgill
Aug 11, 2014, 4:35 PM
You made changes to your sample, so now you should post an updated sample with your current code.

PLEASE REMOVE ALL CODE THAT IS NOT DIRECTLY RELATED TO THE PROBLEM.

Do you need all those Plant recodes to demonstrate the problem? Can the problem still be reproduces with three records?

matrixwebtech
Aug 11, 2014, 5:34 PM
VIEW


@using Ext.Net;
@using Ext.Net.MVC;
@{
var X = Html.X();
Layout = null;
}

<!DOCTYPE html>

<html>
<head>
<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),
X.ModelField().Name("Light").Type(ModelFieldType.String),
X.ModelField().Name("Price").Type(ModelFieldType.Float),
X.ModelField().Name("Availability").Type(ModelFieldType.Date),
X.ModelField().Name("Indoor").Type(ModelFieldType.Boolean)
)

)
)
.ColumnModel(
Html.X().Column().DataIndex("Common").Text("Common Name").Flex(1),
Html.X().Column().DataIndex("Botanical").Text("Botanical").Width(230),
Html.X().Column().DataIndex("Light").Text("Light").Width(130),
Html.X().Column().DataIndex("Price").Text("Price").Width(70).Align(Alignment.Right),
Html.X().DateColumn().DataIndex("Availability").Text("Available").Width(95).Format("yyyy-MM-dd"),
Html.X().Column().DataIndex("Indoor").Text("Indoor?").Width(55)

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


MODEL



using Ext.Net;
using System;
using System.Collections;
using System.Collections.Generic;


public class remotepagingfilter
{

public class Plant
{
public string Common
{
get;
set;
}

public string Botanical
{
get;
set;
}

public string Zone
{
get;
set;
}

public string ColorCode
{
get;
set;
}

public string Light
{
get;
set;
}

public double Price
{
get;
set;
}

public DateTime Availability
{
get;
set;
}

public bool Indoor
{
get;
set;
}

public static Paging<Plant> PlantsPaging(StoreRequestParameters parameters, string filterheader)
{
var data = Plant.GetPlants();

FilterHeaderConditions fhc = new FilterHeaderConditions(filterheader);

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);
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();
}

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

return Plant.PlantsPaging(parameters.Start, parameters.Limit, parameters.SimpleSort, parameters.SimpleSortDirection,null);
}

public static Paging<Plant> PlantsPaging(int start, int limit, string sort, SortDirection dir, string filter)
{
List<Plant> plants = Plant.GetPlants();



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",
Zone = "4",
ColorCode = "E7E7E7",
Light = "Mostly Shady",
Price = 2.44,
Availability = new DateTime(2006, 03, 15),
Indoor = true
},

new Plant
{
Common = "Columbine",
Botanical = "Aquilegia canadensis",
Zone = "3",
ColorCode = "E7E7E7",
Light = "Mostly Shady",
Price = 9.37,
Availability = new DateTime(2006, 03, 06),
Indoor = true
},
new Plant
{
Common = "Marsh Marigold",
Botanical = "Caltha palustris",
Zone = "4",
ColorCode = "F5F5F5",
Light = "Mostly Sunny",
Price = 6.81,
Availability = new DateTime(2006, 05, 17),
Indoor = false
},

new Plant
{
Common = "Cowslip",
Botanical = "Caltha palustris",
Zone = "4",
ColorCode = "E7E7E7",
Light = "Mostly Shady",
Price = 9.90,
Availability = new DateTime(2006, 03, 06),
Indoor = true
},




};
}
}

}



CONTROLLER



public class remotepagingfilterController : Controller
{
//
// GET: /remotepagingfilter/

public ActionResult Index()
{
return View();
}

public ActionResult Read(StoreRequestParameters parameters, string filterheader)
{
return this.Store(remotepagingfilter.Plant.PlantsPaging(p arameters, filterheader));
}

}



I add 4 records to grid ,I search for Mar on first page "Common Name" column and "Marsh Marigold" present in 2nd page but remote filtering not done. may be I am doing some mistakes,but unfortunately I am not able to find it out.

Daniil
Aug 12, 2014, 2:24 PM
The PlantsPaging method looks like this:


public static Paging<Plant> PlantsPaging(StoreRequestParameters parameters, string filterheader)
{
// filtering

return Plant.PlantsPaging(parameters.Start, parameters.Limit, parameters.SimpleSort, parameters.SimpleSortDirection, null);
}

I don't see how you use the filtered data. You just call

public static Paging<Plant> PlantsPaging(int start, int limit, string sort, SortDirection dir, string filter)
which deals with the full data set again and it doesn't know anything about filtration. You should retrieve the current page's records from the filtered data.

matrixwebtech
Aug 12, 2014, 4:07 PM
I am not getting your point properly?please see http://forums.ext.net/showthread.php?41301-Example-need-for-remote-paging-and-filterheader&p=187181#post187181 and suggest me what change I have to do in the code.

Daniil
Aug 12, 2014, 4:28 PM
Ok, I will try to rephrase my point.

The point is the fact that you return non-filtered data here:

return this.Store(remotepagingfilter.Plant.PlantsPaging(p arameters, filterheader));

The .PlantsPaging() method returns non-filtered data.

matrixwebtech
Aug 12, 2014, 4:58 PM
Thanks Daniil ,I setup Plantspagging function like bellow.and its works fine ,this can be close.


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(ite m, 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 (!string.IsNullOrEmpty(filter) && filter != "*")
//{
// plants.RemoveAll(plant => !plant.Common.ToLower().StartsWith(filter.ToLower( )));
//}

//if (!string.IsNullOrEmpty(sort))
//{
// plants.Sort(delegate(Plant x, Plant y)
// {
// object a;
// object b;

// int direction = dir == SortDirection.DESC ? -1 : 1;

// a = x.GetType().GetProperty(sort).GetValue(x, null);
// b = y.GetType().GetProperty(sort).GetValue(y, null);

// return CaseInsensitiveComparer.Default.Compare(a, b) * direction;
// });
//}

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);
}

matrixwebtech
Jan 09, 2015, 10:52 AM
I go through with example explorer to day,at http://mvc2.ext.net/#/GridPanel_Paging_and_Sorting/Remote/ .and see


public static Paging<Plant> PlantsPaging(int start, int limit, string sort, SortDirection dir, string filter)
{
List<Plant> plants = Plant.GetPlants();
every time PlantsPaging first take all data and then display basis on start and limit.that means on every paging click a database interaction occurs .
Say if some grid has 500 records to show and I set pagesize to 30 then page will be (500/30)=17 on every paging click all 500 data will be fetched and display according start and limit.

So,for 17 page 17 times database interaction and each time all record are fetched?in case there are records more then 500 say 5000,then ?17 times request go to server fetch data(5000 records) and display only 30.

please correct me if I wrong.

matrixwebtech
Jan 12, 2015, 8:21 AM
can you please clear my understanding?

Daniil
Jan 13, 2015, 6:06 AM
Sorry for the delay in answering.

Yes, you are correct in your assumptions, but you are free to organize calls to a database as required.