[CLOSED] GridPanel Hiding Columns dynamically

  1. #1

    [CLOSED] GridPanel Hiding Columns dynamically

    Hi

    I want to be able to hide columns in a GridPanel depending on selections made by the user.

    To test this out I've developed a simple example where when I press a button a certain column is hidden. However, it only hides the data in the column.

    If I add '.Hidden(true) against the Column in the ColumnModel it hides the whole column. I must be missing something?

    This is my View:

    <!DOCTYPE html>
    <html>
    <head>
        <title></title>
        <script>
            var test = function (grid) {
                grid.columns[1].hidden = true;
                grid.reconfigure();
           };
        </script>
    </head>
    <body>
    @Html.X().ResourceManager().ScriptMode(Ext.Net.ScriptMode.Debug).SourceFormatting(true)
    @(Html.X().GridPanel().Width(352)
        .Title("Users").ID("GridPanel").Border(true)
        .Store(Html.X().Store()
            .ID("Store")
            .Model(Html.X().Model().ID("Model").IDProperty("ID")
                .Fields(
                    new ModelField("ID", ModelFieldType.Int),
                    new ModelField("Name"),
                    new ModelField("Period")
                    )
                )
            .Proxy(Html.X().AjaxProxy().Url(Url.Action("Read")).Reader(Html.X().JsonReader().RootProperty("data"))))
        .ColumnModel(
            Html.X().Column().Text("Name").DataIndex("Name").Flex(20),
            Html.X().Column().Text("Period").DataIndex("Period").Flex(20).ID("Period")
        )
        .TopBar(
        Html.X().Toolbar()
            .Items(
                        Html.X().Button().Text("Test").Icon(Icon.Delete).Listeners(lst => { lst.Click.Handler = "test(#{GridPanel})"; })
            )
        )
    )
    </body>
    </html>
    This is my Controller:

    using Ext.Net;
    using Ext.Net.MVC;
    using System;
    using System.Collections.Generic;
    using System.Web;
    using System.Web.Mvc;
    
    namespace ExtNetBugsMVC.Controllers
    {
        public class HomeController : Controller
        {
            public ActionResult Index()
            {
                return View();
            }
            public ActionResult Read()
            {
                List<User> lstUsers = new List<User>();
                lstUsers.Add(new User(1000, "Jeff", "00:10"));
                lstUsers.Add(new User(1001, "James", "02:00"));
                return this.Store(lstUsers);
            }
        }
    
        public class User
        {
            public User()
            {
            }
            public User(int id, string name, string period)
            {
                ID = id;
                Name = name;
                Period = period;
            }
            public int ID { get; set; }
            public string Name { get; set; }
            public string Period { get; set; }
        }
    }
    Last edited by Daniil; Dec 14, 2015 at 2:06 PM. Reason: [CLOSED]
  2. #2
    Hi Jeff,

    It looks like a GridPanel's .reconfigure() is not supposed to be called without parameters.
    http://docs.sencha.com/extjs/5.1/5.1...od-reconfigure

    Yes, both the parameters are marked as optional, but I believe it was meant that one of them is mandatory still. It is just not mentioned explicitly.

    This appears to be working.
    var test = function (grid) {
        var columns = grid.initialConfig.columns.items;
    
        columns[1].hidden = true;
        grid.reconfigure(null, columns);
    };
    This does as well:
    var test = function (grid) {
        grid.columns[1].hide();
    };
  3. #3
    Thanks Daniil

    The second option is obviously much simpler so I will use that. Don't know why I didn't think to try that!

    Thanks again

    Jeff
  4. #4
    Hi

    In practice I've found that the second method is relatively slow if you're hiding multiple columns. In this case the first method is much more efficient, For example:

                                var noColumns = list.selection.data.ID;
                                var columns = grid.initialConfig.columns.items;
                                if (startend == "start") {
                                    for (i = 2; i < noColumns + 1; i++) {
                                        columns[i].hidden = true;
                                    }
                                }
                                else {
                                    for (i = noColumns + 2; i < 98; i++) {
                                        columns[i].hidden = true;
                                    }
                                }
                                grid.reconfigure(null, columns);

Similar Threads

  1. [CLOSED] dynamically adding columns to gridpanel
    By sharmav1 in forum 2.x Legacy Premium Help
    Replies: 3
    Last Post: Jun 27, 2015, 9:41 PM
  2. [CLOSED] Migration Hiding columns
    By rmelancon in forum 2.x Legacy Premium Help
    Replies: 1
    Last Post: Jul 02, 2013, 10:30 PM
  3. Hiding Columns in Grid Panel
    By ChrisO in forum 2.x Help
    Replies: 1
    Last Post: Apr 24, 2013, 9:40 AM
  4. Replies: 5
    Last Post: Jan 08, 2013, 11:45 AM
  5. [CLOSED] Problems hiding/showing TreeGrid columns
    By jmcantrell in forum 1.x Legacy Premium Help
    Replies: 12
    Last Post: Sep 13, 2011, 9:24 PM

Posting Permissions