[webcomponent] Multiselect with array

Forum to discuss the new web client version of Servoy.

[webcomponent] Multiselect with array

Postby poyel » Thu Aug 14, 2014 3:47 pm

Hi,
in the training we see how to create a dataprovider in angular (spec file and js file).
We have seen that a dataprovider has a specific dataprovider type.

But my question is:

Is it possible to assign an array or json object as dataprovider now?

For example, if i want to create a new web component like this http://www.bachyaproductions.com/wp-assets/uploads/2014/05/2014-05-17-20.42.47.png, in which the dataprovider is an array of the selected elements passed as dataset, foundset, etc.

You think that is possibile?

Thanks

Bye Bye
Marco Alessio Milazzo
- freelance programmer -
Web Developer
Servoy
poyel
 
Posts: 49
Joined: Wed Aug 31, 2011 4:35 pm

Re: [webcomponent] Multiselect with array

Postby pbakker » Fri Aug 15, 2014 3:52 pm

Hi,

This UI looks to me like a regular Form in ListView mode, which is already supported in the NGClient as well.

If you want to build a component which offers such a UI, there are multiple options, depending on how you want to bind to data:
FoundSet: if you want to make something that binds to a FoundSet, best is to wait a bit, since the current API to work with FoundSets in components is not yet stable and also not documented. But if you're eager to try it out, have a look at the servoydefaults/portal implementation, which is foundset based.
If you want to bind to a DataSet or plain JavaScript object, you can already build such a thing, providing the data through an api method, like setData(dataset) for example.

Hope this helps,

Paul
pbakker
 
Posts: 2822
Joined: Wed Oct 01, 2003 8:12 pm
Location: Amsterdam, the Netherlands

Re: [webcomponent] Multiselect with array

Postby poyel » Tue Sep 23, 2014 8:54 pm

Hi,

I try using api function and work as well.
But for the philosophie of the webcomponents i want to assign data in another way.

i tried to set an Array as dataProvider of the webcomponent.
I add a watcher in the link property of the component but when i add a new entry on dataprovider the listener is not executed.

i try to add a watcher in this way:

Code: Select all
scope.$watch("model.datasetToShow", function(newVal, oldVal){}, true)

and also:
Code: Select all
scope.$wtachColletion("model.datasetToShow", function (newVal, oldVal){})


and in servoy i write a function that add a new entry on dataprovider:

Code: Select all
dataprovider.push(Math.random())


if i provide an array just fill with data the component shows the data in correct way, but if i add new value at runtime i have the same situation.

I have this problem for array and dataprovider.

There is an error on my code? Or if impossibile to use an Array or dataset as dataprovider?

Thanks,
Marco

bye
Marco Alessio Milazzo
- freelance programmer -
Web Developer
Servoy
poyel
 
Posts: 49
Joined: Wed Aug 31, 2011 4:35 pm

Re: [webcomponent] Multiselect with array

Postby jcompagner » Fri Sep 26, 2014 1:59 pm

what is that "dataprovider"

did you assign that to a global variable?

then you have to really reassign that to that global variable (that changed array)

if that is not a dataprovider property but it is more just a spec model property like

":myprop": "string[]"

and you do:

elements.mybean.myprop = ["some","thing"]

then if you do elements.mybean.myprop.push("else");

that should work in the next alpha. for now you really have to reassign it.
Johan Compagner
Servoy
User avatar
jcompagner
 
Posts: 8833
Joined: Tue May 27, 2003 7:26 pm
Location: The Internet

Re: [webcomponent] Multiselect with array

Postby poyel » Fri Sep 26, 2014 2:32 pm

In the spec file of the components i create

Code: Select all
model: {
"dataProviderToShow":"dataprovider"
}


and in jsfile of the form i write:

Code: Select all
var datasetToShow = [];  // as form variable


in a function
Code: Select all
...
datasetToShow.push(Math.random())
...
Marco Alessio Milazzo
- freelance programmer -
Web Developer
Servoy
poyel
 
Posts: 49
Joined: Wed Aug 31, 2011 4:35 pm

Re: [webcomponent] Multiselect with array

Postby jcompagner » Fri Sep 26, 2014 5:30 pm

yes that will not work, because servoy does not see the change

You really have to do dataprovider = xxxx

this is the same thing as doing dataprovider.setTime(xxx) for a date, you have to reassign it, you can't alter some internal state and expect that servoy sees that
Johan Compagner
Servoy
User avatar
jcompagner
 
Posts: 8833
Joined: Tue May 27, 2003 7:26 pm
Location: The Internet

Re: [webcomponent] Multiselect with array

Postby poyel » Fri Sep 26, 2014 5:54 pm

Ok i understand the reason why servoy don't sees the changes of the dataprovider.
So, is more correct to call this variable foundset that dataprovider.

So, the unique way to do that is to create a variable in model section, encapsulate it in set/get methods for read and write the values, and call scope.svyApply("modelVar") for to comunicate the client changes (if there are) on server and sync the values.

Right?

Bye,
Marco
Marco Alessio Milazzo
- freelance programmer -
Web Developer
Servoy
poyel
 
Posts: 49
Joined: Wed Aug 31, 2011 4:35 pm


Return to Servoy NGClient

Who is online

Users browsing this forum: No registered users and 2 guests