EasyUI Forum

General Category => General Discussion => Topic started by: kapil on September 27, 2016, 12:19:13 AM



Title: How to load data from String varibale into datagrid
Post by: kapil on September 27, 2016, 12:19:13 AM
I want to load data from String variable into datagrid in javascript, How can i load it ?

String variable Data is in JSON format.

is it possible to load in following way;
 
Code:
success: function (result) {
                            var json = JSON.parse(result);
                            alert(json.dataCount);
                            alert(json.rsDataRow);
                            $('#adcmSummary').datagrid('load',json.rsDataRow);
                         
                        }

is there any other ways???
i m completely loss.. :-[  :-[


Title: Re: How to load data from String varibale into datagrid
Post by: stworthy on September 27, 2016, 07:50:12 AM
Please call the 'loadData' method to load the existing data.
Code:
$('#adcmSummary').datagrid('loadData', json.rsDataRow);


Title: Re: How to load data from String varibale into datagrid
Post by: Pierre on September 28, 2016, 02:43:03 AM
Hello
is it possible to loadData from file?
I try this:

$('#adcmSummary').datagrid('loadData', 'myfile.json');

but it does not work.
Thank you.


Title: Re: How to load data from String varibale into datagrid
Post by: stworthy on September 28, 2016, 06:56:23 PM
No, you have to request it from the server before loading into the datagrid. It is more simpler to call 'load' or 'reload' method to load data from remote server.
Code:
$('#adcmSummary').datagrid('load', 'myfile.json');


Title: Re: How to load data from String varibale into datagrid
Post by: Pierre on September 28, 2016, 10:47:34 PM
Hello
Look like I don't understand so here is additional info:
I have 'myfile.json' file prepared and ready on server. Then I call it like this:

Code:
$('#adcmSummary').datagrid('load', 'myfile.json');

but it does not work - it does not load data. There is no any error in console. 'reload' and 'loadData' also does not work.

here is how it works:

Code:
$('#adcmSummary').datagrid('loadData', myJsonData);  // myJsonData contains JSON data

What I try to avoid is that server send JSON data back to client because when there is lot of data, server memory grows.. so I wanted to send a file (from server to client) and to load a file into datagrid.
Is that possible?
Thank you.


Title: Re: How to load data from String varibale into datagrid
Post by: stworthy on September 29, 2016, 12:29:59 AM
The 'load' method load data from the remote server while the 'loadData' method load data from the local data. Please confirm if the 'myfile.json' file can be accessed from your browser. Another thing should be mentioned is that some web server does not allowed to visit the static file via 'post' method, so you may need to set the 'method' property to 'get' for the datagrid. Please try to run this code to see if your 'myfile.json' file can be accessed and has a correct format.
Code:
$.getJSON('myfile.json', function(data){
  console.log(data);
});


Title: Re: How to load data from String varibale into datagrid
Post by: Pierre on September 29, 2016, 12:58:03 AM
Hello
thank you for your help.
Yes, I can access the file and it have correct format, when using code you provided (please see image below).
What else I should try, please?


Title: [SOLVED] Re: How to load data from String varibale into datagrid
Post by: Pierre on September 29, 2016, 01:26:55 AM
OMG my JSON file have not corrected format ..  >:( I'm sorry, it works perfect.
Thank you