c# - Dynamically Add Rows in Google Visualization API (JavaScript) -


i working on asp.net mvc 3 project requires me upload a.xls / .xlsx user input, load datatable , place visual of in view.

sounds easy enough...

i able create datatable , pass object view, unable render data table on view via google's visualization api -- of examples have seen require statically denoted fields, i.e.:

var data = new google.visualization.datatable(); data.addcolumn('string', 'task'); data.addcolumn('number', 'hours per day'); data.addrows([   ['work', 11],   ['eat', 2],   ['commute', 2],   ['watch tv', 2],   ['sleep', {v:7, f:'7.000'}] ]); 

however, since application taking user input, column headers, dimensions, , content dynamic. looking way add data dynamically. here code have, model datatable being passed in:

@model system.data.datatable @using gridmvc.html @{     viewbag.title = "file upload";     <h2>@viewbag.message</h2> }  <html>   <head>     <script type='text/javascript' src='https://www.google.com/jsapi'></script>     <script type='text/javascript'>         google.load('visualization', '1', { packages: ['table'] });         google.setonloadcallback(drawtable);         function drawtable( model ) {             var data = new google.visualization.datatable();             var numrows = model.rows.count;             var numcols = model.rows[0].count;              (var = 0; < numcols; i++)                 data.addcolumn('string', model.rows[0].itemarray[i]);              (var = 1; < numrows; i++)                 data.addrow(model.rows[i].itemarray);                       //data.addrows([['2967773', '13-1014428', '', 'not recommended -internship', '7- not recommended',             //                'university 1', '', '', '', '', '', '', '' ]]);              var table = new google.visualization.table(document.getelementbyid('table_div'));             table.draw(data, { showrownumber: true });         }     </script>   </head>    <body>     <div id='table_div'></div>   </body>   <p>done</p> </html> 

does know how this? in advance!

as comment above mentions, datatables c# not same datatables in google api. ended finding third party library (example) handled , passed following viewbag:

viewbag.data = new bortosky.google.visualization.googledatatable(converttable( data )).getjson(); 

Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

ios - Change Storyboard View using Seague -