Forum



15:47

06/12/2011

I am trying to implement an "as shipped" JQGrid search on a referenced field. I am having trouble displaying the text of the referenced Status model, as well as issues with the search not returning any results. Here are the models, map, viewmodel, controller, and view (as modeled after Trirand's demos):
Models:
public class Person { public virtual int Id { get; set; } public virtual int Name{ get; set; } public virtual Status { get; set; } } public class Status { public virtual int Id { get; set; } public virtual int Text{ get; set; } }
Map:
public class PersonMap : ClassMap<Person> { public PersonMap() { Id(t => t.Id); Map(t => t.Name); References(t => t.Status, "StatusID); } }
ViewModel:
public class PersonViewModel { public JQGrid PersonGrid { get; set; } int Id { get; set; } public virtual Status { get; set; } public string Name { get; set; } public PersonViewModel() { PersonGrid = new JQGrid { Columns = new List<JQGridColumn>() { new JQGridColumn { DataField = "Id", DataType = typeof(UInt32), HeaderText = "Id", PrimaryKey = true, Searchable = true, }, new JQGridColumn { DataField = "Status", HeaderText = "Status", DataType = typeof(Status), Searchable = true, }, new JQGridColumn { DataField = "Name", DataType = typeof(string), Searchable = true, } }, }; PersonGrid.ToolBarSettings.ShowSearchToolBar = true; } }
Controller:
public ActionResult Search() { var model = new PersonViewModel(); SetUpGrid(model); return View(model); } public void SetUpGrid(PersonViewModel model) { var PersonGrid = model.PersonGrid; PersonGrid.ID = "PersonGrid"; PersonGrid.DataUrl = Url.Action("PersonDataRequested"); } public JsonResult PersonDataRequested() { var model = new PersonViewModel(); JQGridState gridState = model.PersonGrid.GetState(true); Session["gridState"] = gridState; return model.PersonGrid.DataBind(_session.Query<Person>()); }
View:
@using Trirand.Web.Mvc @model ....PersonViewModel ...standard script/header stuff... <body> @Html.Trirand().JQGrid(Model.PersonGrid, "PersonGrid") </body>
The result I'm getting is that "Castle.Proxies.StatusProxy" is being displayed in the status column for each person in the grid, and no search by status (neither Id nor Text value) returns any results. The searches by the Person fields (Id and Name) work just fine.
17:46

06/12/2011

Ok. Wow. Really sorry about the formatting above. It is better formatted at
http://stackoverflow.com/quest.....bsp;though I don't think that is the
best forum for working with JQGrid.
18:43

06/12/2011

I've resolved the display issue by overriding the ToString() method for Status. As for the search issue, this is
what I've discovered:
What is being returned in both cases is a JSonResult. However, when searched by Status, the query itself
returns the expected results, but when the grid.DataBind executes, the JSonResult.Data member becomes
an Object rather than a JSonResponse. Looking at the query results, I cannot see any difference in types or
structure (or even the data), and hence no reason for the lack of convertion from object to JSonResponse.
Most Users Ever Online: 715
Currently Online:
60 Guest(s)
Currently Browsing this Page:
1 Guest(s)
Top Posters:
OlegK: 1255
markw65: 179
kobruleht: 144
phicarre: 132
YamilBracho: 124
Renso: 118
Member Stats:
Guest Posters: 447
Members: 11373
Moderators: 2
Admins: 1
Forum Stats:
Groups: 1
Forums: 8
Topics: 10592
Posts: 31289
Newest Members:
, razia, Prankie, psky, praveen neelam, greg.valainis@pa-tech.comModerators: tony: 7721, Rumen[Trirand]: 81
Administrators: admin: 66