[CLOSED] MultiCombo

  1. #1

    [CLOSED] MultiCombo

    Hi, i'm trying to linked multicombo with ajax, but i have a problem with that. The second control depends on the first one, i have got the itemlist data, but i cant show the results in the second multicombo




    ComboIndex.cshtml

    @{
        Layout = null;
        var X = Html.X();
    }
    
    <!DOCTYPE html>
    
    <html>
    <head>
        <meta name="viewport" content="width=device-width" />
        <title>ComboIndex</title>
        @using System.Web.Optimization
    
        <link href='https://fonts.googleapis.com/css?family=Open+Sans+Condensed:300' rel='stylesheet' type='text/css'>
        <link href='https://fonts.googleapis.com/css?family=Ubuntu+Condensed' rel='stylesheet' type='text/css'>
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script>
    
    </head>
    <body>
        @model List<Ext.Net.ListItem>
    
        @(X.ResourceManager()
           .Theme(Theme.Neptune)
           .Listeners(ls => { ls.DocumentReady.Handler = "ExtReady();"; })
        )
    
        @(X.Viewport()
             .ID("Viewport1")
             .Layout("FitLayout")
             .StyleSpec("background-color: transparent;")
             .Items(
                   X.FormPanel()
                   .ID("FormPanel1")
                   .AutoScroll(true)
                   .BodyPadding(0)
                   .Border(false)
                   .Items(
                       X.FormPanel()
                        .ID("FormPanelSuperior")
                        .Title("panel superior")
                        .BodyPadding(5)
                        .Layout("ColumnLayout")
                        .Border(true)
                        .IconPath("ImagenIcono")
                        .Items(
                           X.Panel()
                            .ID("panelDetalles1")
                            .Cls("panelDetalles")
                            .Border(false)
                            .ColumnWidth(0.665)
                            .Margin(5)
                            .BodyPadding(5)
                            .Items(
                               X.FieldSet()
                                  .ID("fieldSetDetalles1")
                                  .Cls("campoDetalles")
                                  .DefaultAnchor("100%")
                                  .Title("Detalle")
                                  .ColumnWidth(1)
                                  .StyleSpec("border-color:#157FCC")
                                  .Layout("ColumnLayout")
                                  .Items(
                                    X.Container()
                                    .ID("containerInterno")
                                    .ColumnWidth(.5)
                                    .Items(
                                        X.MultiCombo()
                                          .ID("comboA")
                                          .Editable(false)
                                          .EmptyText("Seleccione...")
                                          .FieldLabel("A")
                                          .LabelAlign(LabelAlign.Left)
                                          .ForceSelection(true)
                                          .Padding(2)
                                          .Flex(1)
                                          .DirectEvents(de =>
                                          {
                                              de.FocusLeave.Action = "FiltrarBusqueda";
                                              de.FocusLeave.ExtraParams.Add(new Parameter("items", "App.comboA.getSubmitArray()", ParameterMode.Raw));
    
                                          })
                                         .Items(
                                          ViewBag.obtenerPaises
                                          ),
    
                                        X.MultiCombo()
                                        .ID("comboB")
                                        .Editable(false)
                                        .Selectable(true)
                                        .FieldLabel("B")
                                        .LabelAlign(LabelAlign.Left)
                                        .Padding(2)
                                        .Flex(1)
                                        )              
                                    )
                               )
                          )
                     )
                  )
                 )
    
    </body>
    
    </html>



    ComboController.cs

    using Ext.Net;
    using System.Collections.Generic;
    using System.Data;
    using System.Linq;
    using System.Web.Mvc;
    using Ext.Net.MVC;
    using System.Text;
    
    namespace iSGCAS_MVC_Razor.Controllers
    {
        public class ComboController : Controller
        {
    
            static DataTable paisesDT = new DataTable();
    
            // GET: Combo
            public ActionResult ComboIndex()
            {
                DataSet ds = new DataSet();
                DataTable dt = new DataTable();
                ds.Tables.Add(dt);
                dt.Columns.Add("nomPais", typeof(string));
                dt.Columns.Add("idPais", typeof(string));
                dt.Rows.Add("Brazil", "BR");
                dt.Rows.Add("Canada", "CA");
                dt.Rows.Add("Chile", "CL");
                ViewBag.obtenerPaises = this.Listar(dt);
    
                return View();
            }
    
            private List<Ext.Net.ListItem> Listar(DataTable paisdt)
            {
                List<Ext.Net.ListItem> paislist = new List<Ext.Net.ListItem>();
                 if (paisdt != null)
                {
                    if (paisdt.Rows.Count > 0)
    
                        foreach (DataRow row in paisdt.Rows)
                        {
                            paislist.Add(new Ext.Net.ListItem(row[0].ToString(), row[1].ToString()));
                        }
                }
                    return paislist;
              
            }
    
            [DirectMethod]
            public ActionResult FiltrarBusqueda()
            {
                List<Ext.Net.ListItem> items = JSON.Deserialize<List<Ext.Net.ListItem>>(Request.Params["items"]);
    
                StringBuilder sb1 = new StringBuilder(256);
                int contador = 0;
                string concatenado = " idPais = ";
    
                sb1.Append("Ext.Msg.alert('Concatenacion', '");
    
                foreach (Ext.Net.ListItem item in items)
                {
                    if (contador == 0)
                    {
                        concatenado = concatenado + "'" +(string)item.Value + "'" ;
                        contador++;
                    }
                    else
                    {
                        concatenado = concatenado + " OR idPais = " + "'" + (string)item.Value + "'";
                        contador++;
                    }
                }
                sb1.AppendFormat(concatenado);
    
                DataSet ds = new DataSet();
                DataTable dt = new DataTable();
                ds.Tables.Add(dt);
                dt.Columns.Add("nomCiudad", typeof(string));
                dt.Columns.Add("idPais", typeof(string));  
                dt.Rows.Add("Fortaleza", "BR");
                dt.Rows.Add("Manaos", "BR");
                dt.Rows.Add("Natal", "BR");
                dt.Rows.Add("Bulgaria", "BG");
                dt.Rows.Add("Toronto", "CA");
                dt.Rows.Add("Regina", "CA");
                dt.Rows.Add("Victoria", "CA");
                dt.Rows.Add("Antofagasta", "CL");
                dt.Rows.Add("Santiago", "CL");
                dt.Rows.Add("Concepcion", "CL");
                dt.Rows.Add("Valparaiso", "CL");
    
                if (concatenado.Equals(" idPais = "))
                {
                    concatenado = "CL";
                }
                else
                {
    
                    DataRow[] row1 = dt.Select(concatenado);
                    DataTable seleccionados = new DataTable();
    
                    seleccionados = row1.CopyToDataTable();
    
                    List<Ext.Net.ListItem> aux = new List<Ext.Net.ListItem>();
    
                    aux = this.Listar(seleccionados);
                    MultiCombo multicombo = X.GetCmp<MultiCombo>("comboA");
    
                    if (aux == null || aux.Count() == 0)
                    {
                        multicombo.Items.Add(new Ext.Net.ListItem(" No hay servicios asociados"));
                    }
                    else
                    {
                        foreach (Ext.Net.ListItem item in aux)
                        {
                            multicombo.Items.Add(item);
                            multicombo.Show();
                            multicombo.DataBind();
    
                        }
                        multicombo.Selectable = true;
                    }
                }
              return this.Direct();
            }
        }
    }
    Last edited by fabricio.murta; Dec 09, 2016 at 2:55 PM.
  2. #2
    Hello @Opendat2000!

    I'm looking after your issue now. Seems the variable you declared in line 14 of your controller code is not used at all, am I right, or maybe something went missing in the code?

    Also, it looks like you are trying to populate ComboA (line 106 of your controller) while you wanted ComboB, am I correct to assume that?..

    Nevertheless, I'm noticing some changes are not being returned to the page when the direct method returns, I'm clarifying the reason for this and will reply shortly.
    Fabrício Murta
    Developer & Support Expert
  3. #3

    reply line 14 and 106.

    Hi,
    Yes, both are my fault, the line 14 is unused code and at the line 106 it should be like this:

                    MultiCombo multicombo = X.GetCmp<MultiCombo>("comboB");
    I'll be waiting for your reply.

    Thanks a lot.
  4. #4
    Hello again @Opendat2000!

    Do you have a special reason you can't base your linked combo boxes from our online example at http://mvc4.ext.net/#/Form_ComboBox/...inked_Combos/?

    Else I don't see much point in spending time in the test case you sent if we already have a working sample doing the same job. :)

    Maybe you didn't know of the MVC version of the ajax linked combos?
    Fabrício Murta
    Developer & Support Expert
  5. #5
    Hello @Opendat2000!

    It's been some days since we last sent you a follow-up here and you didn't provide a feedback. Did the sample above help at all, or you still need help with this issue? We're looking forward for your feedback!
    Fabrício Murta
    Developer & Support Expert
  6. #6
    I found the solution, thank you anyway.

    We used LoadData() to dinamically load store from controller, later we must use a listener when the combobox expanded to reload the store and set the selected item.

    You can close the thread.
  7. #7
    Hello @opendat2000!

    Thanks for the feedback and for sharing the solution that worked for you! Glad you could work out a solution for your problem.
    Fabrício Murta
    Developer & Support Expert

Similar Threads

  1. [CLOSED] MultiCombo with two columns
    By osef in forum 2.x Legacy Premium Help
    Replies: 3
    Last Post: Aug 13, 2015, 8:46 AM
  2. [CLOSED] Multicombo value set by the database
    By ucaneto in forum 2.x Legacy Premium Help
    Replies: 1
    Last Post: Apr 30, 2015, 2:00 PM
  3. MultiCombo and IE8
    By Birgit in forum 2.x Help
    Replies: 1
    Last Post: Dec 07, 2012, 9:15 AM
  4. Coolite.ext.web is having multicombo
    By Nagaraju in forum 1.x Help
    Replies: 1
    Last Post: Sep 23, 2011, 11:48 AM
  5. Select all in MultiCombo
    By skrishnasamy in forum 1.x Help
    Replies: 0
    Last Post: Aug 12, 2010, 7:00 AM

Tags for this Thread

Posting Permissions