My AJAX-enabled WCF service returns JSON using this contract,
[DataContract]
public class JQGridContract
{
[DataContract]
public class Row
{
[DataMember]
public int id { get; set; }
[DataMember]
public List<string> cell { get; set; }
public Row()
{
cell = new List<string>();
}
}
[DataMember]
public int page { get; set; }
[DataMember]
public int total { get; set; }
[DataMember]
public int records { get; set; }
[DataMember]
public List<Row> rows { get; set; }
public JQGridContract()
{
rows = new List<Row>();
}
}
So each row of data in the results is untyped -- a row is essentially just a List without any column names attached.
I think that makes it impossible for me to use the 'jsonmap' attribute of colModel? Basically I am retrieving a DataTable from the database, and then putting that DataTable into this JQGridContract form. Column information from the DataTable isnt contained in the json passed to the client, though.
Id like to be able to map a column of my underlying DataTable to a column of my jqGrid, but without the need to strongly type my data contract. Is this possible? I thought it might be using anonymous types, where a list of anonymous objects (each anonymous object being a row) that have properties corresponding to each column in the underlying DataTable, but I haven't been able to make that work.
Thanks.
EDIT
Here is an example of want I want to achieve (using server-side code, rather than javascript).
Below is essentially a column model for a jqGrid thats done in c#:
return new JQGridColumnCollection()
{
new JQGridColumn()
{
DataField = "ID", // maps to the DataTable
DataType = typeof(int),
HeaderText = "ID",
PrimaryKey = true,
},
new JQGridColumn()
{
DataField = "Name",
DataType = typeof(string),
HeaderText = "Name"
},
new JQGridColumn()
{
DataField = "Birthdate",
DataType = typeof(DateTime),
HeaderText = "Birth Date"
}
};
The 'DataField' property of each column maps that column to a column in the underyling DataTable. The order of the columns in the DataTable could be different:
DataTable table = GetDataTable(" SELECT [Birthdate], [ID], [Name] From PersonTable ");
But regardless of how I query my database, the grid will still show up where the first column is ID, the second column is Name, and the third column is Birthdate. I dont have to change my SQL query in order to change the order of the columns in my grid.
I essentially want the equivalent of a DataField property in my client-side colModel for the jqGrid. That would require that my JSON columns are named, or that I can atleast map a jqGrid column to the numerical index of a column in the JSON data source.