[CLOSED] Example need for remote paging and filterheader

Page 1 of 2 12 LastLast
  1. #1

    [CLOSED] Example need for remote paging and filterheader

    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 https://examples2.ext.net/#/GridPane...Header/Remote/ in MVC Razor syntax.
    Last edited by Daniil; Jan 16, 2015 at 9:21 AM. Reason: [CLOSED]
  2. #2
    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.
    Geoffrey McGill
    Founder
  3. #3
    I follow http://mvc.ext.net/#/GridPanel_Pagin...orting/Remote/

    And prepare a test case.but I will not figure out how to implement remote filter.I found here(https://examples2.ext.net/#/GridPane...Header/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(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 ------------------------------------------------------------
                   
                    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(parameters,filterheader));
            }
    
        }
    }
    Last edited by matrixwebtech; Aug 11, 2014 at 1:11 PM.
  4. #4
    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)
  5. #5
    I change my code at http://forums.ext.net/showthread.php...921#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
    Last edited by matrixwebtech; Aug 11, 2014 at 1:29 PM.
  6. #6
    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?
  7. #7
    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.
  8. #8
    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?
    Geoffrey McGill
    Founder
  9. #9

    Current Code

    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(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 ------------------------------------------------------------
    
                    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(parameters, 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.
    Last edited by matrixwebtech; Aug 12, 2014 at 3:03 PM.
  10. #10
    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.
Page 1 of 2 12 LastLast

Similar Threads

  1. SqlDataSource remote paging
    By asics167 in forum 2.x Help
    Replies: 7
    Last Post: Oct 28, 2013, 12:57 PM
  2. Replies: 11
    Last Post: Jun 13, 2012, 4:53 PM
  3. [CLOSED] Remote paging with handler.
    By stoque in forum 1.x Legacy Premium Help
    Replies: 21
    Last Post: Aug 16, 2011, 2:27 AM
  4. [CLOSED] LinqDataSource and remote paging
    By John_Writers in forum 1.x Legacy Premium Help
    Replies: 2
    Last Post: Apr 28, 2011, 11:22 AM
  5. [CLOSED] Row expander with remote paging
    By 78fede78 in forum 1.x Legacy Premium Help
    Replies: 1
    Last Post: Jan 31, 2011, 12:31 PM

Posting Permissions