PDA

View Full Version : [CLOSED] Store Problem



adelaney
May 16, 2012, 5:28 PM
I have a Store:


@(Html.X.Store().ID("EmployeeData") _
.DataSource(ViewData("Employees")) _
.Model(Sub(mdl)
mdl.Add(Html.X.Model.Fields(Sub(flds)
flds.Add("Text")
flds.Add("Value")
End Sub))
End Sub))

And I have a grid where I want the store to be used as the source in a column editor, so I am trying to set the editor's store to the ID of my predefined one.

cols.Add(Html.X.Column().DataIndex("DrafterEmployeeID").Text("Drafter1").Editor(Sub(edt)
Dim cbo As New Ext.Net.ComboBox
With cbo
.ID = "DrafterEmployeeID"
.StoreID = "EmployeeData"
.MultiSelect = False
.AutoDataBind = True
.TypeAhead = True
.DisplayField = "Text"
.ValueField = "Value"
End With
edt.Add(cbo)
End Sub))

When I run the page, I keep getting an error that the store (with ID "EmployeeData") cannot be found. I do have the store definied before the grid and when I view the source for the page, I see this:


window.App.EmployeeData=Ext.create("Ext.data.Store",{model:Ext.define(Ext.id(), {extend: "Ext.data.Model", fields:[{name:"Text"},{name:"Value"}] }),storeId:"EmployeeData",autoLoad:true,proxy:{data:...

What are some possibilities as to why my grid having trouble finding the store?

Daniil
May 16, 2012, 7:44 PM
Hi,

The fix has been added to SVN, please update and retest.

Thanks for the report!

adelaney
May 17, 2012, 3:18 PM
The code no longer complains about being unable to find the storeID, but now it has made the App (javascript) object invalid. All my javascript is broken. :(

Daniil
May 17, 2012, 4:47 PM
it has made the App (javascript) object invalid.

Could you provide more details? Posting a sample to reproduce the problem would be best.

adelaney
May 17, 2012, 5:23 PM
Here is the specific error:

invalid property id
[Break On This Error]
...peAhead:true,valueField:"Value",{raw}store:EployeeData},text:"Drafter"},{dataInd...
Line 46

(The error arrow points specifically to the first { in "{raw}")

Also, I don't know if this matters, but this store and grid are in a partial view.

Daniil
May 17, 2012, 8:09 PM
Thanks for the report. We are working on the fix.

Vladimir
May 17, 2012, 9:45 PM
Fixed in SVN. Please update and retest

adelaney
May 18, 2012, 2:55 PM
It still does not render. Now, I have this error: "EmployeeData is not defined" with the javascript break not being indicated, so I don't know where the problem is. I do have output, but I cannot share that data in a public forum as it contains some real employee data. At this point, I am unsure how to proceed.

Vladimir
May 18, 2012, 3:18 PM
Well, I think i know what the problem. You store instance is App.EmployeeData (with App namespace) therefore combo cannot find it.
I will add support for id with namespace soon



I do have output, but I cannot share that data in a public forum as it contains some real employee data.

We don't required real data, you can alwayse to replace it by test data

I will post notification today about fix

adelaney
May 18, 2012, 3:28 PM
That did it. If I go back into the code and make the StoreID="App.EmployeeData", it works. Now the question is how do I get the combo to recognize my EmployeeID as the selected value? I have .AutoDataBind = True. Do I need to manually set the .Value property, and if so, how do I get the row's current EmployeeID value?


cols.Add(Html.X.Column().DataIndex("DrafterEmployeeID").Text("Drafter").Editor(Sub(edt)
Dim cbo As New Ext.Net.ComboBox
With cbo
.ID = "DrafterEmployeeID"
.StoreID = "App.EmployeeData"
.MultiSelect = False
.AutoDataBind = True
.TypeAhead = True
.DisplayField = "Text"
.ValueField = "Value"
End With
edt.Add(cbo)
End Sub))

Daniil
May 18, 2012, 3:59 PM
Now the question is how do I get the combo to recognize my EmployeeID as the selected value?

Please clarify what is the "EmployeeID"? Where does it come form and how do you want to use it?

If I understand the problem correctly, you should use a custom Renderer for the Column.

Please see the Department Column.
http://examples2.ext.net/#/GridPanel/Data_Presentation/Editor_Field_Mapping/

adelaney
May 18, 2012, 5:48 PM
That was really helpful. However, as I am trying to duplicate this example, I am getting nothing rendered to the grid. On closer inspection, I see that this javascript line:


var r = App.EmployeeData.getById(value)
Returns "Null." In setting up my store, I did set the JSON reader IDProperty to "Value" and as I use Firebug to review the script, I can use

App.EmployeeData.getAt(0)
to return this data:

Object { internalId="7752", raw={...}, data={...}, more...}
But

App.EmployeeData.getById(7752)
and

App.EmployeeData.getById("7752")
both return null. Am I missing something, or is this another bug?

Daniil
May 18, 2012, 6:08 PM
Could you please post the Store configuration and a data you bind to that Store?

adelaney
May 18, 2012, 7:00 PM
I will gladly post the store configuration:


@(Html.X.Store().ID("EmployeeData") _
.DataSource(ViewData("Employees")) _
.Reader(Sub(rdr)
rdr.Add(New Ext.Net.JsonReader() With {.IDProperty = "Value"})
End Sub) _
.Model(Sub(mdl)
mdl.Add(Html.X.Model.Fields(Sub(flds)
flds.Add("Text")
flds.Add("Value")
End Sub))
End Sub))

However, the data is real employee data. It wouldn't be within corporate policy for me to post that - especially in a public forum. However, here is how I get the data.

From the Controller:

Private Sub PopulateEmployeeList(Optional ByVal selectedID As Integer = 0)
Dim memberListItems As SelectList
Using mgr As New Utilities.ServiceManager
memberListItems = mgr.Team.GetMemberListBoxItems(selectedID)
ViewData("Employees") = memberListItems.ToList()
End Using

End Sub

Which calls a service:

<OperationContract(), WebGet()> _
<OutputCache(CacheProfile:="hour", Location:=OutputCacheLocation.ServerAndClient, VaryByParam:="none")> _
Public Function GetMemberListBoxItems(Optional ByVal selectedID As Integer = 0) As IEnumerable(Of SelectListItem)
Thread.Sleep(1000)

Return New SelectList((New CWTeamMember).LoadList(), dataValueField:="EmployeeID", dataTextField:="Name", selectedValue:=selectedID)
End Function


The result is data which looks like this:

{data:[{"Selected":false,"Text":"Employee1, Fake","Value":"7752"},{"Selected":false,"Text":"Employee2, Fake2","Value":"5273"},{"Selected":false,"Text":"Employee3, Fake3","Value":"7457"},

And for good measure, here is the column configuration:

cols.Add(Html.X.Column().DataIndex("DrafterEmployeeID").Text("Drafter").Renderer(New Ext.Net.Renderer() With {.Fn = "employeeRenderer"}).Editor(Sub(edt)
Dim cbo As New Ext.Net.ComboBox
With cbo
.ID = "DrafterEmployeeID"
.StoreID = "App.EmployeeData"
.Value =
.MultiSelect = False
.AutoDataBind = True
.QueryMode = DataLoadMode.Local
.TypeAhead = True
.DisplayField = "Text"
.ValueField = "Value"
End With
edt.Add(cbo)
End Sub))

And the updated Renderer is this:

var employeeRenderer = function (value) {
debugger;
var r = App.EmployeeData.getById(value);

if (Ext.isEmpty(r)) {
return "";
}

return r.data.Text;
};

Daniil
May 18, 2012, 7:21 PM
Thanks.

Setting up

IDPropery="Value"
for the Store Model instead of JsonReader should solve the problem.

Vladimir
May 18, 2012, 8:09 PM
StoreID fix is committed to SVN, now a store should be resolved correctly by id under Razor

adelaney
May 21, 2012, 1:56 PM
I have updated my store to this:

@(Html.X.Store().ID("EmployeeData") _
.DataSource(ViewData("Employees")) _
.Reader(Sub(rdr)
rdr.Add(New Ext.Net.JsonReader())
End Sub) _
.Model(Sub(mdl)
mdl.Add(Html.X.Model.Fields(Sub(flds)
flds.Add("Text")
flds.Add("Value")
End Sub).IDProperty("Value"))
End Sub))
However, the value still comes back null from this code:

var employeeRenderer = function (value) {
debugger;
var r = App.EmployeeData.getById(value);

if (Ext.isEmpty(r)) {
return "";
}

return r.data.Text;
};

At this point, I am not sure what else to do. Please advise.

Daniil
May 21, 2012, 2:11 PM
Please provide a full sample to reproduce replacing any private data with some dummy one.

adelaney
May 21, 2012, 2:21 PM
I found the issue.

Just as a wild guess, I started searching to determine if there were a way to set a datatype on the store fields, once I found that there was, I altered my store to this:

@(Html.X.Store().ID("EmployeeData") _
.DataSource(ViewData("Employees")) _
.Reader(Sub(rdr)
rdr.Add(New Ext.Net.JsonReader())
End Sub) _
.Model(Sub(mdl)
mdl.Add(Html.X.Model.Fields(Sub(flds)
flds.Add("Text")
flds.Add("Value", Ext.Net.ModelFieldType.Int)
End Sub).IDProperty("Value"))
End Sub))

Then, it started working. Sorry for the extra post and bother. However, hopefully this will be beneficial to someone else new to your product.

Daniil
May 21, 2012, 2:24 PM
Thanks for the update.