[CLOSED] Grid filters not submitted on DirectEvents

Page 2 of 2 FirstFirst 12
  1. #11

    Sample

    Ok,

    Here we go :

    Controller

      public class AttachmentsController : Controller
      {
        TicketAttachmentViewModel[] data = new[] { new TicketAttachmentViewModel() { 
          CreationDate = DateTime.Today,
          FileName = "First",
          Guid = new Guid(),
          Id = 1
        },
        new TicketAttachmentViewModel() { 
          CreationDate = DateTime.Today,
          FileName = "Second",
          Guid = new Guid(),
          Id = 2
        },
        new TicketAttachmentViewModel() { 
          CreationDate = DateTime.Today,
          FileName = "Third",
          Guid = new Guid(),
          Id = 3
        },
        new TicketAttachmentViewModel() { 
          CreationDate = DateTime.Today,
          FileName = "Fourth",
          Guid = new Guid(),
          Id = 4
        }
        };
    
        public ActionResult Index()
        {
          return View(data);
        }
    
        public ActionResult AttachmentsDownload(string code, Ext.Net.StoreRequestParameters parameters)
        {
          X.Msg.Notify("Filters value ", Request.Params["filter"]).Show(); 
          return this.Direct();
        }
      }
    View Model :

      public class TicketAttachmentViewModel
      {
        public Nullable<int> Id { get; set; }
        public Guid Guid { get; set; }
        public string FileName { get; set; }
        public Nullable<DateTime> CreationDate { get; set; }
        public Nullable<int> Size { get; set; }
      }
    Index.cshtml:

    @model IEnumerable<TicketAttachmentViewModel>
    @{
      Layout = "~/Views/Shared/_Layout.cshtml";
    }
    
    @(
    
     Html.X().Viewport().Layout(LayoutType.Border).Items(vpItems =>
    {
      vpItems.Add(
        Html.X().GridPanel()
        .ID("attachmentsGrid")
        .Region(Region.Center)
        .Store(
    
          Html.X().Store().ID("attachmentsStore")
    
          .DataSource(Model)
          .Model(
    
            Html.X().Model().Fields(
              new ModelField("CreationDate", ModelFieldType.Date),
              new ModelField("FileName"),
              new ModelField("Size", ModelFieldType.Int),
              new ModelField("Guid", ModelFieldType.Auto)
            )
    
          ).Sorters(
    
            Html.X().DataSorter().Property("FileName").Direction(Ext.Net.SortDirection.ASC)
    
          )
    
        ).ColumnModel(
    
          Html.X().DateColumn().Text("Created On").DataIndex("CreationDate").Align(Alignment.Center),
          Html.X().Column().Text("FileName").DataIndex("FileName").Flex(1),
          Html.X().Column().Text("Size").DataIndex("Size").Renderer(RendererFormat.FileSize).Align(Alignment.Right)
    
        ).Features(
    
          Html.X().GridFilters().Filters(
    
            Html.X().DateFilter().DataIndex("CreationDate").DatePickerOptions(dpo => dpo.TodayText = "Now"),
            Html.X().StringFilter().DataIndex("FileName")
          ).Local(true)
    
        ).View(
    
          Html.X().GridView().StripeRows(true).TrackOver(true)
    
        ).TopBar(
    
          Html.X().Toolbar().Items(
            Html.X().Label().Text("Attachments").Cls("x-panel-header-text x-panel-header-text-default"),
            Html.X().ToolbarFill(),
    
            //Html.X().Button()
            //    .Text("To XML")
            //    .Icon(Icon.PageCode)
            //    .Handler("exportData(this.up('grid'));"),
    
            Html.X().Button()
              .Text("Download")
              .IconCls("#Compress")
              .DirectEvents(de =>
              {
                de.Click.Url = Url.Action("AttachmentsDownload");
                de.Click.IsUpload = true;
                de.Click.ExtraParams.Add(new Parameter
                {
                  Name = "code",
                  Value = ViewBag.TicketCode,
                  Mode = ParameterMode.Value,
                });
    
                de.Click.ExtraParams.Add(new Parameter
                {
                  Name = "filter",
                  Value = "this.up('grid').filters.getFilterData()",
                  Mode = ParameterMode.Raw,
                });
    
                de.Click.ExtraParams.Add(new Parameter
                {
                  Name = "sort",
                  Value = "this.up('grid').store.getSorters()",
                  Mode = ParameterMode.Raw
                });
              }
            )
          )
        )
    
        .BottomBar(Html.X().PagingToolbar().DisplayInfo(true).EmptyMsg("No Elements").HideRefresh(true))
    
      );
    })
    )
    Layout :

    <!DOCTYPE html>
    <html lang="en">
    <head>
      <meta charset="utf-8" />
      <title>Test APP</title>
      <link href="~/favicon.ico" rel="shortcut icon" type="image/x-icon" />
      <meta name="viewport" content="width=device-width" />
      @RenderSection("head", required: false)
    </head>
    <body>
      @Html.X().ResourceManager().CleanResourceUrl(true)
      @RenderBody()
      @RenderSection("scripts", required: false)
    </body>
    </html>
    Let me know if you need more info.

    Regards,
    Alberto.
  2. #12
    Thank you.

    I realized that StoreRequestParameters works with native Store filters only, not with GridFilters. We will investigate a possibility to support it.

    For now, please use:
    public ActionResult Action(string filter)
    {
         if (!string.IsNullOrEmpty(filter))
         {
             FilterConditions fc = new FilterConditions(filter);
         }
    }
    Last edited by Daniil; Nov 13, 2012 at 2:44 PM.
  3. #13

    FilterConditions

    Hi Daniil,

    If I use the FilterConditions I get the following exceptions :

       at Ext.Net.FilterCondition.set_Property(JProperty value) in c:\Projects\Ext.Net\Ext.Net\Ext\UX\GridFilters\FilterConditions.cs:line 117
       at Ext.Net.FilterConditions.ParseConditions() in c:\Projects\Ext.Net\Ext.Net\Ext\UX\GridFilters\FilterConditions.cs:line 63
       at Ext.Net.FilterConditions..ctor(String filtersStr) in c:\Projects\Ext.Net\Ext.Net\Ext\UX\GridFilters\FilterConditions.cs:line 37
       at ExtNetFilterSample.Controllers.AttachmentsController.AttachmentsDownload(String code, StoreRequestParameters parameters) in c:\Projects\Tests\ExtNetFilterSample\ExtNetFilterSample\ExtNetFilterSample\Controllers\AttachmentsController.cs:line 49
       at lambda_method(Closure , ControllerBase , Object[] )
       at System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters)
       at System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters)
       at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters)
       at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass42.<BeginInvokeSynchronousActionMethod>b__41()
       at System.Web.Mvc.Async.AsyncResultWrapper.<>c__DisplayClass8`1.<BeginSynchronous>b__7(IAsyncResult _)
       at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResult`1.End()
       at System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethod(IAsyncResult asyncResult)
       at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass37.<>c__DisplayClass39.<BeginInvokeActionMethodWithFilters>b__33()
       at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass4f.<InvokeActionMethodFilterAsynchronously>b__49()

    UPDATE :

    The problem is that the filter json format is not those that the FilterConditions is expecting so the fields value are null.

    Regards,
    Alberto.
    Last edited by AlbertoCe; Nov 13, 2012 at 2:03 PM.
  4. #14
    Please set up this Before handler for the DirectEvent instead of the "filter" Parameter.
    Before="var f = App.GridPanel1.filters; 
            Ext.apply(extraParams, f.buildQuery(f.getFilterData()));"
Page 2 of 2 FirstFirst 12

Similar Threads

  1. [Razor] Example for grid filters
    By Natalie in forum 2.x Help
    Replies: 4
    Last Post: Apr 23, 2012, 9:22 AM
  2. Replies: 3
    Last Post: Jan 12, 2012, 3:26 PM
  3. [CLOSED] Hidden Change and Grid Filters are not working after Grid Reconfigure
    By speedstepmem3 in forum 1.x Legacy Premium Help
    Replies: 15
    Last Post: Oct 16, 2011, 1:12 PM
  4. Replies: 16
    Last Post: Feb 23, 2011, 10:03 AM
  5. Grid filters in code-behind
    By petlun in forum 1.x Help
    Replies: 4
    Last Post: Jan 01, 2009, 2:40 PM

Tags for this Thread

Posting Permissions