[CLOSED] Update gridpanel datasource from controller

  1. #1

    [CLOSED] Update gridpanel datasource from controller

    Hi,
    I need to update gridpanel datasource from controller with another data, but I get an error when I try to assign the new list.

    This is the error :
    Click image for larger version. 

Name:	Captura.PNG 
Views:	99 
Size:	43.8 KB 
ID:	25314


    My GridPanel Code
    @model  SLINETWEB.ViewModels.ManifestViewModel
    @{ 
    
        Layout = "~/Views/Shared/_BaseLayout.cshtml";
    }
    
    @(
    
        Html.X().Viewport()
            .ID("ViewPortManifest")
            .Layout(LayoutType.Border)
            .PaddingSpec("10 10 10 10")
            .Items(
                Html.X().FieldSet()
                .ID("FilterPanel")
                .Title("Filtros de Búsqueda")
                .Region(Region.North)
                .Height(225)
                .Layout(LayoutType.Column)
                .FieldDefaults((fd) =>
                {
                    fd.LabelWidth = 150;
                    fd.LabelStyle = "font-weight:bold;";
                })
                .Items(
                    Html.X().FieldContainer()
                    .MarginSpec("10 0 0 30")
                    .Padding(5)
                    .Layout(LayoutType.HBox)
                    .Items(
                        Html.X().DateFieldFor(m => m.ManifestRequest.DAT_STARTDATE).ID("StartDateField").FieldLabel("Fecha Desde").AllowBlank(false),
                        Html.X().DateFieldFor(m => m.ManifestRequest.DAT_ENDDATE).ID("EndDateField").FieldLabel("Fecha Hasta").MarginSpec("0 0 0 70").AllowBlank(false),
                        Html.X().TextFieldFor(m => m.ManifestRequest.VCH_DIRECTMASTERGUIDE).ID("MasterGuideField").FieldLabel("Número GuÃ*a").MarginSpec("0 0 0 70")
                        ),
                    Html.X().FieldContainer()
                    .MarginSpec("10 0 0 30")
                    .Padding(5)
                    .Layout(LayoutType.HBox)
                    .Items(
                        Html.X().TextFieldFor(m => m.ManifestRequest.VCH_CONSIGNEE).ID("ConsigneeField").FieldLabel("Consignatario"),
                        Html.X().TextFieldFor(m => m.ManifestRequest.VCH_SHIPPER).ID("ShipperField").FieldLabel("Exportador").MarginSpec("0 0 0 70"),
                        Html.X().TextFieldFor(m => m.ManifestRequest.VCH_DESCRIPTION).ID("Productield").FieldLabel("Producto").MarginSpec("0 0 0 70")
                        ),
                    Html.X().FieldContainer()
                    .Padding(5)
                    .MarginSpec("10 0 0 30")
                    .Layout(LayoutType.HBox)
                    .Items(
                        Html.X().TextFieldFor(m => m.ManifestRequest.VCH_AIRLINE).ID("AirlineField").FieldLabel("AerolÃ*nea"),
                        Html.X().TextFieldFor(m => m.ManifestRequest.VCH_DESTINATION).ID("DestinationeField").FieldLabel("Destino").MarginSpec("0 0 0 70"),
                        Html.X().NumberFieldFor(m => m.ManifestRequest.INT_WEEK).ID("WeekField").FieldLabel("Semana").MarginSpec("0 0 0 70")
                        )
                    ),
                    Html.X().GridPanel()
                    .ID("GridPanelManifest")
                    .Region(Region.Center)
                    .EmptyText("<center> No se encontraron resultados</center>")
                    .TopBar(
                            Html.X().Toolbar()
                            .Items(
                                Html.X().Button()
                                .ID("SearchButton")
                                .Text("Buscar")
                                .IconCls("x-fa fa-search")
                                .ToolTip("<b> Buscar (Ctrl+B)</b> </br> Busca Manifiestos")
                                .DirectEvents(de => {
                                    de.Click.Url = Url.Action("SearchManifests");
                                    de.Click.EventMask.ShowMask = true;
                                    de.Click.FormID = "FilterPanel";
                                })
                                ,
                                Html.X().ToolbarFill(),
                                Html.X().Button()
                                .ID("NewButton")
                                .Text("Exportar")
                                .IconUrl("../../Assets/images/icons/excel.svg")
                                .ToolTip("<b>Exportar</b>")
                                )
                            ).Store(
                                Html.X().Store()
                                .ID("ManifestStore")
                                .Model(Html.X().Model()
                                .AutoDataBind(true)
                                .IDProperty("ID")
                                .Fields(
                                    new ModelField("INT_MANIFESTID", ModelFieldType.Int),
                                    new ModelField("DAT_DEPARTUREDATE", ModelFieldType.Date),
                                    new ModelField("INT_DAY", ModelFieldType.Int),
                                    new ModelField("INT_MONTH", ModelFieldType.Int),
                                    new ModelField("INT_YEAR", ModelFieldType.Int),
                                    new ModelField("INT_WEEK", ModelFieldType.Int),
                                    new ModelField("VCH_AIRLINE", ModelFieldType.String),
                                    new ModelField("VCH_FLIGHTNUMBER", ModelFieldType.String),
                                    new ModelField("VCH_MANIFESTNUMBER", ModelFieldType.String),
                                    new ModelField("VCH_AIRGUIDE", ModelFieldType.String),
                                    new ModelField("VCH_DIRECTMASTERGUIDE", ModelFieldType.String),
                                    new ModelField("VCH_DESCRIPTION", ModelFieldType.String),
                                    new ModelField("VCH_TERMINALCODE", ModelFieldType.String),
                                    new ModelField("DEC_MANIFESTEDWEIGHT", ModelFieldType.Float),
                                    new ModelField("INT_MANIFESTEDPACKAGE", ModelFieldType.Int),
                                    new ModelField("DEC_WEIGHTRECEIVED", ModelFieldType.Float),
                                    new ModelField("INT_PACKAGERECEIVED", ModelFieldType.Int),
                                    new ModelField("VCH_CONSIGNEE", ModelFieldType.String),
                                    new ModelField("VCH_SHIPPER", ModelFieldType.String),
                                    new ModelField("VCH_ORIGIN", ModelFieldType.String),
                                    new ModelField("VCH_DESTINATION", ModelFieldType.String),
                                    new ModelField("VCH_ANOTHERAGENT", ModelFieldType.String)
    
                                )).DataSource(Model.Manifests)
                            ).ColumnModel(
                                Html.X().Column().Text("ID").DataIndex("INT_MANIFESTID").Hidden(true),
                                Html.X().DateColumn().Text("Fecha Salida").DataIndex("DAT_DEPARTUREDATE").Width(100),
                                Html.X().Column().Text("DÃ*a").DataIndex("INT_DAY").Width(50),
                                Html.X().Column().Text("Mes").DataIndex("INT_MONTH").Width(50),
                                Html.X().Column().Text("Año").DataIndex("INT_YEAR").Width(50),
                                Html.X().Column().Text("Semana").DataIndex("INT_WEEK").Width(80),
                                Html.X().Column().Text("AerolÃ*nea").DataIndex("VCH_AIRLINE").Width(80),
                                Html.X().Column().Text("Vuelo").DataIndex("VCH_FLIGHTNUMBER").Width(80),
                                Html.X().Column().Text("Manifiesto").DataIndex("VCH_MANIFESTNUMBER").Width(100),
                                Html.X().Column().Text("GuÃ*a Aerea").DataIndex("VCH_AIRGUIDE").Width(100),
                                Html.X().Column().Text("GuÃ*a Master").DataIndex("VCH_DIRECTMASTERGUIDE").Width(100),
                                Html.X().Column().Text("Descripción").DataIndex("VCH_DESCRIPTION").Width(120),
                                Html.X().Column().Text("Código Terminal").DataIndex("VCH_TERMINALCODE").Width(130),
                                Html.X().Column().Text("Peso Manifestado").DataIndex("DEC_MANIFESTEDWEIGHT").Width(130),
                                Html.X().Column().Text("Bultos Manifestado").DataIndex("INT_MANIFESTEDPACKAGE").Width(140),
                                Html.X().Column().Text("Peso Recibido").DataIndex("DEC_WEIGHTRECEIVED").Width(130),
                                Html.X().Column().Text("Bultos Recibido").DataIndex("INT_PACKAGERECEIVED").Width(130),
                                Html.X().Column().Text("Consignatario").DataIndex("VCH_CONSIGNEE").Width(130),
                                Html.X().Column().Text("Embarcador").DataIndex("VCH_SHIPPER").Width(130),
                                Html.X().Column().Text("Origen").DataIndex("VCH_ORIGIN").Width(70),
                                Html.X().Column().Text("Destino").DataIndex("VCH_DESTINATION").Width(70),
                                Html.X().Column().Text("Otro agente").DataIndex("VCH_ANOTHERAGENT").Width(100)
                            ).BottomBar(
                            Html.X().PagingToolbar()
                                .DisplayInfo(true)
                                .DisplayMsg("Displaying plants {0} - {1} of {2}")
                                .EmptyMsg("No plants to display")
    
                                )
                )
            )

    Controller Code

    using Ext.Net;
    using Ext.Net.MVC;
    using SLINETWEB.Models.Manifest;
    using SLINETWEB.Proxy.Manifest;
    using SLINETWEB.ViewModels;
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Linq;
    using System.Threading.Tasks;
    using System.Web;
    using System.Web.Mvc;
    
    namespace SLINETWEB.Controllers.Manifest
    {
        public class ManifestController : Controller
        {
            private readonly ManifestProxy _proxy;
            //private ManifestViewModel _manifestViewModel;
            public ManifestController()
            {
                _proxy = new ManifestProxy();
                //_manifestViewModel = new ManifestViewModel();
            }
            // GET: Manifest
            public ActionResult Index()
            {
                var response = System.Threading.Tasks.Task.Run(() => _proxy.GetManifestsAsync());
                ManifestViewModel manifestViewModel = new ManifestViewModel();
                manifestViewModel.Manifests = response.Result.List;
                manifestViewModel.ManifestRequest = new ManifestRequest();
                return View(manifestViewModel);
            }
    
            public ActionResult SearchManifests(ManifestRequest manifestRequest)
            {
                var response = System.Threading.Tasks.Task.Run(() => _proxy.FindManifestsAsync(manifestRequest));
                var store = X.GetCmp<Store>("ManifestStore");
                store.DataSource = response.Result.List;
                store.DataBind();
                return this.Direct();
            }
        }
    }
    Last edited by fabricio.murta; Mar 10, 2020 at 9:44 PM.
  2. #2
    Hello @pvera, and welcome to Ext.NET forums!

    Your example is almost as great as simple and runnable, except for the definitions of ManifestProxy, ManifestViewModel.

    So I just can't run the example and tell you why exactly it does not work. If what I am to say next wouldn't help you at all, please review the test case either stubbing out the undisclosed code, removing them (if this does not affect the reproducibility), or changing it to simple bare static data. The answer is based on similar behavior from your description and what I could infer from reading your test case.

    For what I see in your case comparing to a similar situation we highlight in GridPanel > ArrayGrid > Remote Load, you'd need to, instead of getting the grid and data-binding it as we would in WebForms, you can just return the store itself and then use a client-side helper to properly bind the data.

    It is always not the only and only way to implement something in Ext.NET MVC, but that's an approach you could adapt your code to quickly have it working; an approach we have among our examples in Examples Explorer (as linked above).

    The points of interest of the example pointed are the onSuccess() client method and the Load Data button in the view code; then GetData() action in the controller code.

    Hope this helps! If still stuck, please review the example allowing us to run it locally, and we'll promptly work on it.
    Fabrício Murta
    Developer & Support Expert
  3. #3
    Thank you Fabricio, that example worked for me :).
  4. #4
    Glad it helped, thanks for the feedback, we really appreciate it!
    Fabrício Murta
    Developer & Support Expert

Similar Threads

  1. Replies: 2
    Last Post: Apr 11, 2012, 11:10 AM
  2. Replies: 5
    Last Post: Feb 01, 2012, 11:54 AM
  3. update datasource for grid with conbobox value
    By rlasker3 in forum 1.x Help
    Replies: 0
    Last Post: Jun 06, 2010, 9:35 PM
  4. How to Update the GridPanel data to the DataSource
    By animalisme in forum 1.x Help
    Replies: 2
    Last Post: Jun 22, 2009, 3:09 AM
  5. how to update xml datasource in GridPanel?
    By bruce in forum 1.x Help
    Replies: 2
    Last Post: Oct 30, 2008, 1:08 PM

Tags for this Thread

Posting Permissions