PDA

View Full Version : [CLOSED] Client side error databinding Store



vadym.f
Jul 19, 2013, 3:46 PM
Hi,

I'm receiving a JS error when data binding a Store on the server. The error is thrown when a typed DataTable doesn't contain any records. There's no error when at least one row is present in the data source. I'm not sure where to look for clues or pointers. A nearly identical set up works for me with no issues whatsoever. Please advise if more info is required here. 6577



protected void Page_Load(object sender, EventArgs e)
{
if (ExtNet.IsAjaxRequest) return;

var dataSource=GetTypedDataTable();
this.Store1.DataSource = dataSource;
this.Store1.DataBind();
}




<Store>
<ext:Store runat="server" ID="Store1" PageSize="20">
<Model>
<ext:Model ID="Model1" runat="server" IDProperty="ID">
<Fields>
<ext:ModelField Name="ID" Type="Int" />
<ext:ModelField Name="Message" Type="String" />
<ext:ModelField Name="CreatedDate" Type="Date" RenderMilliseconds="true" />
</Fields>
</ext:Model>
</Model>
<Sorters>
<ext:DataSorter Property="CreatedDate" Direction="DESC" />
</Sorters>
</ext:Store>
</Store>

vadym.f
Jul 19, 2013, 4:25 PM
I've figured it out. The call causing the error was on my side:



var selectedValues = grid.getRowsValues({
currentPageOnly: true,
selectedOnly: true
});

var sm = grid.getSelectionModel();
if (sm && selectedValues.length == 0) {
grid.getSelectionModel().selectRange(0, 0); // Error was thrown here
}


With no records in the Store, selectRange(0, 0) would fail producing the error description that kept me puzzled for a while. I've augmented the check in my code to avoid it as below:



var selectedValues = grid.getRowsValues({
currentPageOnly: true,
selectedOnly: true
});

var sm = grid.getSelectionModel();
if (sm && selectedValues.length == 0 && grid.getStore().count()!=0) {
grid.getSelectionModel().selectRange(0, 0);
}


You can mark this question as closed.