EasyUI Forum
March 28, 2024, 04:15:14 AM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News:
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: How to load data from String varibale into datagrid  (Read 14296 times)
kapil
Newbie
*
Posts: 3


View Profile Email
« 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.. Embarrassed  Embarrassed
Logged
stworthy
Administrator
Hero Member
*****
Posts: 3581


View Profile Email
« Reply #1 on: September 27, 2016, 07:50:12 AM »

Please call the 'loadData' method to load the existing data.
Code:
$('#adcmSummary').datagrid('loadData', json.rsDataRow);
Logged
Pierre
Sr. Member
****
Posts: 439


View Profile Email
« Reply #2 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.
Logged
stworthy
Administrator
Hero Member
*****
Posts: 3581


View Profile Email
« Reply #3 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');
Logged
Pierre
Sr. Member
****
Posts: 439


View Profile Email
« Reply #4 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.
Logged
stworthy
Administrator
Hero Member
*****
Posts: 3581


View Profile Email
« Reply #5 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);
});
Logged
Pierre
Sr. Member
****
Posts: 439


View Profile Email
« Reply #6 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?
Logged
Pierre
Sr. Member
****
Posts: 439


View Profile Email
« Reply #7 on: September 29, 2016, 01:26:55 AM »

OMG my JSON file have not corrected format ..  Angry I'm sorry, it works perfect.
Thank you
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines Valid XHTML 1.0! Valid CSS!