[webcomponent] Multiselect with array

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

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

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:

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

and also:

scope.$wtachColletion("model.datasetToShow", function (newVal, oldVal){})

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

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

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.

In the spec file of the components i create

model: {
"dataProviderToShow":"dataprovider"
}

and in jsfile of the form i write:

var datasetToShow = []; // as form variable

in a function

...
datasetToShow.push(Math.random())
...

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

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