PDA

View Full Version : [CLOSED] Selecting a row in a non-rendered gridpanel may cause an error



bogc
Oct 03, 2014, 12:48 AM
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.Mod els;

namespace Ext.Net.MVC.Examples.Areas.GridPanel_ArrayGrid.Sim ple.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")
)

)
)
}

Daniil
Oct 03, 2014, 8:24 AM
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/#!/api/Ext.panel.Table-event-viewready

They say

(use this for selecting a default row)

bogc
Oct 03, 2014, 6:20 PM
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.