PDA

View Full Version : [CLOSED] MVC GridPanel Databinding



adelaney
May 14, 2012, 5:30 PM
Is there a way to set a "proxy method" each for Insert, Read, Update & Delete? I see that you have ".Reader" and ".Writer" by default, but I would really like to have some flexibilty with that if possible. For example, my reader method can take an ID parameter and I would like to be able to use a dropdown to select different employee IDs and then rebind/filter my grid. Also, I have to perform different data manipulations on various data elements and those are different whether the action at hand is an update vs. an insert. At any rate, here is my grid configuration. Any advice is appreciated.



Html.X.GridPanel().ID("TeamGrid").ColumnModel(Sub(cols)
cols.Add(Html.X.Column().DataIndex("CWTeamID").Hidden(True))
cols.Add(Html.X.Column().DataIndex("Name").Text("Team").Flex(1))
cols.Add(Html.X.Column().DataIndex("DrafterEmployeeID").Text("Drafter1"))
cols.Add(Html.X.Column().DataIndex("ReviewerEmployeeID").Text("Reviewer"))
cols.Add(Html.X.Column().DataIndex("CorrespondentEmployeeID").Text("Correspondent"))
cols.Add(Html.X.Column().DataIndex("QAReviewerEmployeeID").Text("QA Reviewer"))
cols.Add(Html.X.CommandColumn().Text("Manage").Flex(1).Commands(Sub(commands)
commands.Add(New Ext.Net.GridCommand() With {.Icon = Icon.Pencil, .Text = "Edit"})
commands.Add(New Ext.Net.GridCommand() With {.Text = "Cedents"})
End Sub))
End Sub) _
.Store(Sub(str)
str.Add(Html.X.Store().ID("tmStore").AutoLoad(True) _
.Model(Sub(mdl)
mdl.Add(Html.X().Model.Fields(Sub(fields)
fields.Add(Html.X.ModelField.Name("CWTeamID").Type(ModelFieldType.Int))
fields.Add(Html.X.ModelField.Name("Name"))
fields.Add(Html.X.ModelField.Name("DrafterEmployeeID").Type(ModelFieldType.Int))
fields.Add(Html.X.ModelField.Name("ReviewerEmployeeID").Type(ModelFieldType.Int))
fields.Add(Html.X.ModelField.Name("CorrespondentEmployeeID").Type(ModelFieldType.Int))
fields.Add(Html.X.ModelField.Name("QAReviewerEmployeeID").Type(ModelFieldType.Int))
End Sub))
End Sub) _
.Proxy(Sub(proxy)
proxy.Add(Html.X.AjaxProxy().Url(Url.Content("~/Assignments") + "/_GetTeams/" + MvcApplication.CurrentApplicationUser.EmployeeID.T oString()) _
.Reader(Sub(rdr)
rdr.Add(Html.X.JsonReader().Root("Data"))
End Sub) _
.Writer(Sub(wrtr)
wrtr.Add(Html.X.JsonWriter().Root("Data"))
End Sub))
End Sub) _
.PageSize(20))
End Sub) _
.Listeners(Sub(lstner)
lstner.SelectionChange().Fn = "RowSelected"
End Sub) _
.Loader(Sub(ldr)
ldr.Enabled() = True
End Sub) _
.Plugins(Sub(plug)
plug.Add(New Ext.Net.RowEditing() With {.AutoCancel = False, .ClicksToMoveEditor = 1, .AutoDataBind = True, .SaveBtnText = "Update"})
End Sub) _
.TopBar(Sub(tb)
Dim tbar As New Ext.Net.Toolbar
Dim btn As New Ext.Net.Button() With {.ID = "btnAddTeam", .Text = "Add Team"}
btn.Listeners.Click.Fn = "addTeam"

tbar.Items.Add(btn)
tb.Add(tbar)
End Sub) _
.Selectable(True)

Just to be clear, my goal is to use URL routes like so:
/Assignments/_GetTeams/1
/Assignments/_GetTeams/121
/Assignments/_EditTeams/1
/Assignments/_DeleteTeams/1
/Assignments/_NewTeam/

Timothy
May 14, 2012, 9:15 PM
You should use the API property of the AjaxProxy class, it exposes the Create/Destroy/Read/Update properties that you can bind your URLs for. That is how you would handle a true RESTful pattern with the store.

Cheers,
Timothy

Daniil
May 14, 2012, 9:17 PM
Hi,

Please use the AjaxProxy API.
http://docs.sencha.com/ext-js/4-1/#!/api/Ext.data.proxy.Server-cfg-api