[CLOSED] Selecting a row in a non-rendered gridpanel may cause an error

  1. #1

    [CLOSED] Selecting a row in a non-rendered gridpanel may cause an error

    Hi:

    To reproduce run the code below and click on the Click Me button (don't go to the second tab before clicking the botton).

    I modified the MVC GridPanel/ArrayGrid/Simple sample.

    The error that is thrown is: Uncaught TypeError: Cannot read property 'indexOf' of undefined.

    When you reproduce the error you'll get the full stack.

    The reason I am mentioning this is that it didn't use to fail with an error in Ext.Net 2.1.1.

    Thanks

    using System;
    using System.Collections;
    using System.Web.Mvc;
    using Ext.Net.MVC.Examples.Areas.GridPanel_ArrayGrid.Models;
    
    namespace Ext.Net.MVC.Examples.Areas.GridPanel_ArrayGrid.Simple.Controllers
    {
        public class SimpleController : Controller
        {
            public ActionResult Index()
            {
                return View(Companies.GetAllCompanies());
            }
    
          public StoreResult GetData()
          {
            object[] allCompanies = Companies.GetAllCompanies();
            Array.Reverse(allCompanies);
            return this.Store(allCompanies, allCompanies.Length);
          }
        }
    
        
    }

    @using System.Web.UI.HtmlControls
    @model System.Collections.IEnumerable
    
    @{
        ViewBag.Title = "Simple Array Grid - Ext.NET MVC Examples";
        Layout = "~/Views/Shared/_BaseLayout.cshtml";
    }
    
    @section headtag
    {
        <style>
            .x-grid-row-over .x-grid-cell-inner {
                font-weight : bold;
            }
        </style>
    
        <script>
            var template = '<span style="color:{0};">{1}</span>';
    
            var change = function (value) {
                return Ext.String.format(template, (value > 0) ? "green" : "red", value);
            };
    
            var pctChange = function (value) {
                return Ext.String.format(template, (value > 0) ? "green" : "red", value + "%");
            };
        </script>  
    }
    
    @section example
    {    
        <h1>Simple Array Grid x</h1>
      
      
      @(Html.X().Store()              
          .ID("companiesStore")     
          .Model(Html.X().Model()
              .Fields(
                  new ModelField("company"),
                  new ModelField("price", ModelFieldType.Float),
                  new ModelField("change", ModelFieldType.Float),
                  new ModelField("pctChange", ModelFieldType.Float),
                  new ModelField("lastChange", ModelFieldType.Date, "M/d hh:mmtt")
              )
          )
          .Proxy(
              Html.X().AjaxProxy().Url("~/GridPanel_ArrayGrid/Simple/GetData").Reader(Html.X().ArrayReader().Root("data"))
          )
          )
    
      @(
      Html.X().TabPanel()
          .DeferredRender(true)
          .TopBar(Html.X().Toolbar().Items(
            Html.X().Button()
              .Text("Click me")
                .Listeners(l => l.Click.Handler = "#{secondGridPanel}.bindStore(#{companiesStore}); #{secondGridPanel}.getSelectionModel().select(0);")
          ))
          .Items(
            Html.X().GridPanel()
            .Title("Array Grid 1")
            .Width(600)
            .Height(350)
            .Store(Html.X().Store()
                .Model(Html.X().Model()
                    .Fields(
                        new ModelField("company"),
                        new ModelField("price", ModelFieldType.Float),
                        new ModelField("change", ModelFieldType.Float),
                        new ModelField("pctChange", ModelFieldType.Float),
                        new ModelField("lastChange", ModelFieldType.Date, "M/d hh:mmtt")
                    )
                )
                .DataSource(Model)
            )
            .ColumnModel(
                Html.X().Column().Text("Company").DataIndex("company").Flex(1),
                Html.X().Column().Text("Price").DataIndex("price").Renderer(RendererFormat.UsMoney),
                Html.X().Column().Text("Change").DataIndex("change").Renderer("change"),
                Html.X().Column().Text("Change").DataIndex("pctChange").Renderer("pctChange"),
                Html.X().DateColumn().Text("Last Updated").DataIndex("lastChange")
            ),
            Html.X().GridPanel()
              .Title("Array Grid 2")
              .ID("secondGridPanel")
              .Width(600)
              .Height(350)
              .ColumnModel(
                  Html.X().Column().Text("Company").DataIndex("company").Flex(1),
                  Html.X().Column().Text("Price").DataIndex("price").Renderer(RendererFormat.UsMoney),
                  Html.X().Column().Text("Change").DataIndex("change").Renderer("change"),
                  Html.X().Column().Text("Change").DataIndex("pctChange").Renderer("pctChange"),
                  Html.X().DateColumn().Text("Last Updated").DataIndex("lastChange")
              )
    
          )
      )
    }
    Last edited by Daniil; Oct 04, 2014 at 7:39 AM. Reason: [CLOSED]
  2. #2
    Hi @bogc,

    Rows should not be selected in a non-rendered grid. It should be done in a ViewReady listener, at least.

    Please take a look:
    http://docs.sencha.com/extjs/4.2.1/#...vent-viewready

    They say
    (use this for selecting a default row)
  3. #3
    Rows should not be selected in a non-rendered grid. It should be done in a ViewReady listener, at least.
    I definitely agree with you. Somehow I missed this spot because it worked fine in the previous version.

    Thank you for the information. I am going to keep in mind from now on.

Similar Threads

  1. Replies: 2
    Last Post: Sep 17, 2013, 11:57 PM
  2. Replies: 0
    Last Post: Jun 01, 2013, 10:41 AM
  3. Selecting different columnmodel for gridpanel.
    By masudcseku in forum 1.x Help
    Replies: 5
    Last Post: May 11, 2011, 5:09 PM
  4. Blank GridPanel Rendered
    By iltwams in forum 1.x Help
    Replies: 1
    Last Post: Sep 24, 2010, 7:13 PM
  5. [CLOSED] Error selecting item on ComboBox using icons
    By flormariafr in forum 1.x Legacy Premium Help
    Replies: 3
    Last Post: Mar 05, 2010, 9:25 AM

Posting Permissions