jQWidgets Forums
jQuery UI Widgets › Forums › Getting Started › dynamic dataadapter
This topic contains 3 replies, has 2 voices, and was last updated by Martin 6 years, 6 months ago.
-
Authordynamic dataadapter Posts
-
Hi guys,
i would like to get all data in one request and then render multiple grids and charts from same source changing only root filed in source.
here is my source.var srcSD = { url: "App/Model/Results.php?action=getSD", datatype: 'json', cache: false, autoBind: true, async: true, datafields: [ { name: 'rv', type: 'string' }, { name: 'r', type: 'number' }, { name: 'SC1', type: 'number' }, { name: 'OCC', type: 'number' }, { name: 'LT', type: 'number' }, { name: 'TC', type: 'number' }, ] };
source returns json as:
{"rc 1": [{"rv":0.001,"r":16.769280759046,"SC1":52.742414005073,"OCC":27.87669537958,"TC":42.339785029238,"LT":400.61131126466}, {"rv":0.1,"r":18.656486899499,"SC1":52.935577043711,"OCC":30.534028732456,"TC":43.340537325638,"LT":109.09902937702}, {"rv":0.25,"r":22.398665496225,"SC1":53.228248314373,"OCC":34.560291388327,"TC":44.9405017343,"LT":65.320310170032}, {"rv":0.5,"r":30.85295101876,"SC1":53.716033765478,"OCC":41.270729148114,"TC":47.847862935341,"LT":56.252035611448}], "rc 2": [{"rv":0.001,"r":18.91377781858,"SC1":55.929228829525,"OCC":17.971373454491,"TC":47.151091671193,"LT":437.63386124987}, {"rv":0.1,"r":21.155827237564,"SC1":56.050200015234,"OCC":21.8539339116,"TC":47.98768831736,"LT":195.92159197258}, {"rv":0.25,"r":25.210724200077,"SC1":56.233489690551,"OCC":27.736601270855,"TC":49.313237933854,"LT":88.697791198524}], "rc 3": [{"rv":0.001,"r":46.439798047975,"SC1":60.899041551034,"OCC":52.667990300699,"TC":58.181574926128,"LT":247.28471341936}, {"rv":0.1,"r":47.012282986144,"SC1":60.899041551034,"OCC":53.483680064246,"TC":58.430744572453,"LT":114.61367460441}, {"rv":0.25,"r":48.268093887452,"SC1":60.899041551034,"OCC":54.719573645377,"TC":58.816355476823,"LT":72.066133100989}] }
Now I would like to render grid and charts depending on names rc 1, rc 2 and rc3 (one grid and chart for rc 1, one grid and chart for rc 2…)because I have all data.
$.each(reactors, function (id, reactor) { let reactorVar = reactor.replace(/\s/g, ""); srcSD.root = reactor; daSD = new $.jqx.dataAdapter(srcSD); chart = ChartSettings(daSD, reactor); grid = GridSettings(daSD); $('#jqxChart'+reactorVar).jqxChart(chart); $("#jqxGrid"+reactorVar).jqxGrid(grid); });
As you can see I set root of source and initialize dataadapter but it only gets last value of reactor.
What am I doing wrong here?
Even in this case I would make three request to server. Is it possible to do it only ones and then populate grid and chart using different chunks of data already in source.Thanks a lot
cheersHello atomic,
You need to use a separate data adapter for each widget you initialize, so they can work as expected.
So, to make only one request to the server, I would suggest you to load the data with an ajax request, create 3 different sources and then
create a separate dataAdapter for each widget (one for the grid and one for the chart).Best Regards,
MartinjQWidgets Team
http://www.jqwidgets.com/Hello Martin,
Thanks for the reply. That is one way, but number of grids and charts differ, there can be three bu also any number, that is why I use $.each to loop through number of reactors and initialize grids and charts. Actually my code works well if I use async: false in srcSD, but if I use async: true (as in the example above) I get all grids and charts rendered but with values of the last reactor (rc 3)…
any ideas?
ThanksHello atomic,
As mentioned above, you need a separate data adapter for each component.
I see that in your$.each
loop you are reassigning the newly created data adapter to the samedaSD
variable every time.
This may be the reason why only the last values are loaded in all grids and charts whenasync
is true.
Try creating new variable on each loop:daSD = new $.jqx.dataAdapter(srcSD);
.Best Regards,
MartinjQWidgets Team
http://www.jqwidgets.com/ -
AuthorPosts
You must be logged in to reply to this topic.