jQuery UI Widgets › Forums › General Discussions › Plugins › Data Adapter › values source field not updated on dataBind()?
This topic contains 4 replies, has 2 voices, and was last updated by jcwren 10 years, 4 months ago.
-
Author
-
In the example below, I’m unclear how to cause the
playersSource‘ssh_age_fmtvalues to update when theagesAdapteris updated. WhenrefreshGameData()is called,agesSource.localdatais updated, but when I dumpplayerSource.datafields [1].values.source, the contents are the original value from theagesarray. It appears this might be a copy rather than a reference, otherwise whenagesAdapter.recordswas updated afteragesAdapter.dataBind()is called, it would reflect the change?At any rate, do you have any suggestions for how to cause the
agesAdapter.recordsused by theplayerAdapterto update?$(function () { 'use strict'; var ages = [ { value: 'ADULT', label: 'Adult', }, { value: 'JUNIOR', label: 'Junior', }, { value: 'SENIOR', label: 'Senior', }, ]; var agesSource = { datatype: 'array', datafields: [ { name: 'value', type: 'string' }, { name: 'label', type: 'string' }, ], localdata: ages, }; var agesAdapter = new $.jqx.dataAdapter (agesSource, { autoBind: true }); var playerSource = { datatype: 'array', datafields: [ { name: 'sh_age', type: 'string' }, { name: 'sh_age_fmt', value: 'sh_age', values: { source: agesAdapter.records, value: 'value', name: 'label' }}, ], localdata: [], }; var playerAdapter = new $.jqx.dataAdapter (playerSource); var refreshGameData = function () { App.socket.emit ('game:get', function (data) { agesSource.localdata = data.gameData.ages; agesAdapter.dataBind (); playerSource.localdata = data.gameData.players; $(grid).jqxGrid ({source: playerAdapter}); }); }; });Hi jcwren,
With this code, they shouldn’t be. If you wish they to be updated, you should set them.
Best Regards,
Peter StoevjQWidgets Team
http://www.jqwidgets.comYes, that’s my question. Within the jqx frankwork, what is the *correct* way to handle that? Something like the following?
playerSource.datafields [_.findIndex (playerSource.datafields, {name: 'sh_age_fmt'})].values.source = agesAdapter.records;Or do you have a more correct suggestion?
Hi jcwren,
It would be better if you move your adapters creation code within 1 function and call it when you need your data updated so it will return new adapter instance each time. Otherwise, Yes, you should update the values, because the adapter cannot know that you changed some Array somewhere in your code.
Best Regards,
Peter StoevjQWidgets Team
http://www.jqwidgets.comOK, I can do that.
There are other places in the various widgets where you can pass either a jqxDataAdapter or an array. If would be nice if the source field could handle that also. That way, regardless of when the agesAdapter is updated, any time the playerSource referenced the sh_age_fmt field, it would pick up the most current agesAdapter records. This would also be more consistent with the way it appears dataAdapters are intended to be used.
-
AuthorPosts
You must be logged in to reply to this topic.