JQGrid with xml file as data source - asp.net-mvc

How can I edit a xml file using JQGrid? I am using ASP.Net MVC 3.5 with C#. Is it possible to return a JSon object from controller method for this purpose?

Everything is possible. But the most work which you have to do is independ from the jqGrid. Moreover general XML file can be not good represented in a grid. If the deepness of the XML file not so long, you can use subgrid feature of the jqGrid. One more restriction existing in the jqGrid can make the work more comple: jqGrid not support data with attributs other as ids. So if you will have to map attributes to the sub-elements on the server side to be able to use jqGrid.
The ASP.NET MVC site can for example read the XML file with respect of some desirialization methods and initialize the object with the same information as the XML has. Then can use the object to fill the jqGrid and modify the data. Because th data are no mo represented as a XML, the server can use JSON to communicate with the jqGrid. At the end one can use one from wel known serialization methods so save modified data in the XML file back.

Related

Sorting/Paging/Filtering callback action parameters are empty using Custom Data Binding with DevExpress MVC GridVIew extension

I'm trying to get the DevExpress grid view extension working using custom data binding with an existing ASP.NET MVC 3 site. I've read through and followed the steps in this guide in the DevExpress documentation, but when I try to page, sort or filter, the column information in the GridViewPagerState or GridViewColumnState objects that are bound to the callbacks used to handle these operations come back with default (blank) column information.
I can run the "simple custom data binding" and "advanced custom data binding" demos from the demo center application - these both work as expected. When I transplant the code into my application though, it doesn't work.
How can I get past this?
It turns out I was missing the setup of the DevExpressEditorsBinder in my Global.asax.cs file. Unfortunately I skimmed over this highlighted note taken from the Custom Data Binding - Overview:
Note
When implementing the grid's custom data binding, the DevExpressEditorsBinder must be used instead of the default model binder to correctly transfer values from DevExpress editors back to the corresponding data model fields. See the Binding to Model section in the Binding Data Editors to Data topic for more details on how to specify DevExpressEditorsBinder as a model binder.

struts2 and dojo grid

I need an example for populating the dojo grid with the data coming from server. I have struts2 and dojo application in which action class is setting a model variable of type hashmap as the result containing different values that needs to be shown in the form of grid.
Now how can i represent this hashmap in the form of grid data. can you please giving a sample example application which converts the hashmap to json and then uses this json to populate the grid.
I use Jackson to serialize to JSON. Does each item in the map represent a row in the grid? How complex is the data that you are serializing?
https://github.com/FasterXML/jackson-core
If the data structure is simple, then you can probably get away with just using Jackson.
When you want to begin serializing more complex data structures, then you might need to enhance your serialization engine.
I have written some stuff that can do this. Too much to explain here but you can check out these blog posts and see the code on git hub:
http://swingingcode.blogspot.com/2012/04/json-serialization-engine-part-i.html
http://swingingcode.blogspot.com/2012/04/json-serialization-engine-part-ii.html
https://github.com/cswing/evinceframework/tree/master/web/src/java/com/evinceframework/web/dojo/json

Knockout - How to set Observable Property to JSON REsult from asp.net MVC

The MVC application returns a JSON REsult which contains a JSON object. For knockout 2 way binding to work it requires ko.observable("value").
Is there a way we can set two way binding to the JSON Object returned from MVC?
While you can manually loop through your structure and create appropriate observables, you will probably want to look at the mapping plugin described here: http://knockoutjs.com/documentation/plugins-mapping.html

Model binding to DataTable with no underlying database

I am bootstrapping myself through my very first ASP MVC project, and could use some suggestions regarding the most appropriate (data-side) model binding solution I should pursue. The project is 'small', which really just means I have very limited time for chasing down dead-ends, which cramps my available learning curve. Thanks heaps for reading!
Background: a simple address search app (ASP.NET MVC 3) that sends user form input to a vendor-sourced server, and presents the results returned from the server in a rules-driven format. There is no CRUD-style repository as such; this is an entirely read-only application. The vendor's .NET server API specifies the use DataTable objects (System.Data.DataTable) for both requests and replies.
Currently: I have a prototype under construction to validate server behavior and inform the application's design. There is a conventional MVC data model class for the input form which works great, auto-binding with the view just as you'd expect. When submitted, the controller passes this input model to my vendor API wrapper, which is currently binding to the request table medieval-style:
public DataTable GetGlobalCandidateAddresses(AddressInputModel input)
{
...
DataRow newRow = dataTable.NewRow();
newRow[0] = input.AddressLine1;
newRow[1] = input.AddressLine2;
newRow[2] = input.AddressLine3;
...
dataTable.Rows.Add(newRow);
...
This works fine; the inputs are fixed and have very light validation requirements. However, if there is a modern framework solution for quickly reflecting a DataTable from my model, that would be peachy.
My real conundrum, however, is on the reply. The table returned by the server contains a variable column-set, with any combination of at least 32 possible unordered fields on a per-transaction basis. Some of the column names contain compiler-invalid characters ("status.description") that won't map literally to a model property name. I will also have a need to dynamically map or combine some of the reply fields in the view model, based on a series of rules (address formats vary considerably by country), so not all fields are 1-to-1.
Just to get the prototype fired up and running, I am currently passing the reply DataTable instance all the way back to a strongly-typed view, which spins it out into the display exactly as is. This is nice for quickly validating the server replies, but is not sufficient for the real app (much less satisfying best practices!).
Question: what is my best tooling approach for binding DataTable rows and columns into a proper model class for display in a view, including some custom binding rules, where no underlying database is present?
Virtually all of the training materials I am consuming discuss classic database repository scenarios. The OnModelCreating override available in the Entity Framework seems ideal in some respects, but can you use a DBContext without a DB connection or schema?
If I have to roll my own model binder, are there any tricks I should consider? I've been away from .NET for a while (mostly Java & SQL), so I'm picking up LINQ as I go as well as MVC.
Thanks again for your attention!
Create a poco display model AddressDisplay and do custom object mapping from the data table to the display model. You can use data annotations for formatting but you can also do that in your custom mapping. You shouldn't need to create a custom model binder.
So create two poco models, AddressInput and AddressDisplay, you can use data annotations on AddressInput for validation. When AddressInput is posted back, map it to the outbound data table. When the response is received, map the inbound data table to AddressDisplay and return the view to the user.

MVC - Datagrid binding without a model

Ok, I'll explain. I need to create a datagrid in MVC on the fly (potentially multiple datagrids on a view) depending on a XML file being read in. The file gets looped through and may contain multiple grids of data, the headers and rows are set in the file. The problem being that my application won't know the content of the XML file before reading it so I can't apply it to an IEnumerable model. The idea being to make it generic so that it can read in any XML file I pass to it set up as below and put the data in a sortable datagrid. Is this at all possible with current controls out there? I have tried Teleriks MVC grid and while I can read the data into the grid, I cannot sort the data as this feature will only work when passed a DTO. I have a feeling what I'm looking for can't be done (unless I write a custom HTMLHelper or something) but no harm in asking I guess
My xml will be as such
<xml>
<REPORT>
<HEADERS>
<HEAD>Col1</HEAD>
<HEAD>Col2</HEAD>
</HEADERS>
<ROWS>
<ROW>Data1</ROW>
<ROW>Data2</ROW>
</ROWS>
</REPORT>
</xml>
Thanks
I would advise using the jquery grid. Then write a class to parse the xml and generate the grid javascript in the view, and a second action to parse the xml (again) and generate the json result. MVCCrud may help with the idea there is a generic jquery grid in there but it works off an IQueryable list so would need to be adapted.
I haven't seen a helper extension out there that does what you need.
There are some good ones that work with generic collections (such as Telerik's or MVCContrib's). The sample you provide cannot be translated in to a collection that would be handled by these however: the row needs to have cells that can be matched to the header elements.
<xml>
<REPORT>
<HEADERS>
<HEAD>Col1</HEAD>
<HEAD>Col2</HEAD>
</HEADERS>
<ROWS>
<ROW><CELL>Data1</CELL><CELL>Data2</CELL></ROW>
<ROW><CELL>Data2</CELL><CELL>Data4</CELL></ROW>
</ROWS>
</REPORT>
</xml>
If the XML can be deserialized into a generic collection, it is easy to populate the grid.
Hope this helps.
I'd look into the JQuery Grid. You have to munge the data into the format that it wants, but it gives you a lot of flexibility and nice UI for free. You will still need to write sort code, though.

Resources