Click here to Skip to main content
15,890,186 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm looking for an equivalent of the WinForms DataGridView data binding with automatic column detection, for a jquery datagrid which will extract the columns from the json data input without me defining it.

All the examples I have seen are like :
JavaScript
jQuery("#jsonmap").jqGrid({ 
url:'server.php?q=4', 
datatype: "json", 
colNames:[
'Inv No','Date', 'Client', 'Amount','Tax','Total','Notes'], 
colModel:[ 
{name:'id',index:'id', width:55}, 
{name:'invdate',index:'invdate', width:90, jsonmap:"invdate"}, 
{name:'name',index:'name asc, invdate', width:100}, 
{name:'amount',index:'amount', width:80, align:"right"}, 
{name:'tax',index:'tax', width:80, align:"right"}, 
{name:'total',index:'total', width:80,align:"right"}, 
{name:'note',index:'note', width:150, sortable:false} ], 
rowNum:10, 
rowList:[10,20,30], 
pager: '#pjmap', 
sortname: 'id', 
viewrecords: true, sortorder: "desc", 
jsonReader: { repeatitems : false, id: "0" }, 
caption: "JSON Mapping", height: '100%' }); 
jQuery("#jsonmap").jqGrid('navGrid','#pjmap',{edit:false,add:false,del:false});

Which define the columns before binding .
Posted
Updated 12-Nov-13 7:38am
v2
Comments
Sergey Alexandrovich Kryukov 12-Nov-13 13:06pm    
Sorry, Mehdi, I don't know what is the method WinForms.DataGrid.RetrieveStructure, I suspect it does not exist.
Also, if this is, by any chance, System.Windows.Controls.DataGrid (still there is no RetrieveStructure()), I would strongly discourage using it, favoring DataGridView (yes, I know this is unrelated to your question).

So, if you simply explain what do you want to achieve, maybe I'll be able to help...

—SA
Mehdi Gholam 12-Nov-13 13:13pm    
Sorry I got DataGridView with another component, but my problem is that I need to display a json list of rows in a visually appealing js web grid without defining the columns beforehand as most of the examples I have seen so far seem to do.
Sergey Alexandrovich Kryukov 12-Nov-13 13:26pm    
But this is just the behavior of the HTML "table" element. What's the problem? You simply need to generate appropriate HTML. jQuery provides everything you need. And listen to my advice: fix your question before someone down-votes it for the gibberish-like text it contains... It's easy to reformulate the problem in more correct way.
—SA
Mehdi Gholam 12-Nov-13 13:38pm    
Fixed the question.
Sergey Alexandrovich Kryukov 12-Nov-13 14:42pm    
Very good, thank you.

Honestly, I don't see a problem. First of all, JSON is the native format to JavaScript. So, no need to use any parser, you just use JavaScript eval function, to get it deserialized into an object. And then, you can use jQuery to generate table element with all its structure on the fly, right into DOM. Which part of it seems to be a problem?

—SA

1 solution

Please see my comments to the question. Basically, you get the data and read it while writing HTML, inner HTML of some block element like div (http://api.jquery.com/html/[^]), using API from jQuery category "manipulation": http://api.jquery.com/category/manipulation/[^].

—SA
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900