I have a form with two tabpanel,
a left navigation tabpanel in list view with a media field (images) and a checkbox and
a right tabpanel in record view with many text/combo fields related to the image for catalog them.
My idea is that a user can make a checkbox multiple selection of images, push button update, lock the left tab, user fill the fields and then push button save (a method that copy the filled fields for all checked image record).
The only solution I found is to create a service field in database called “checked” for store the check 1/0 information for every record, but this is not so stylish.
After that I have to create another form with a grid (no idea how to do this) of images and related checkboxes and when a user push a button I have to create a zip of the selected images.
In short, how can I make a backend stylish multiselection in list view?
How can I create a grid of images and handle multiselection?
up, no one have an idea? Or you are all on holiday?
Hello Axterics,
So if I understand you correctly, you want to put a field on the form that indicates a kind of record selection, but w/o storing it in the database correct?
One option is to create a form/global variable which holds a reference to selected records in memory. Then create a calculation “is_selected” which checks f the record is contained in the object.
You can then display a check box field forr this calc.
Make it editable and attach an onDataChange handler to it which toggles its membership in the selection variable.
This example uses an object/associative array.
The underscore is used to prevent java script from interpreting as a regular indexed array.
- Form var selection object to hold in memory:
var selections = new Object();
- is_selected calculation
if(selections['_' + record_id])
return 1;
return 0;
- checkbox onDataChange handler
// get changed value
var selected = arguments[1];
// record was selected
if(selected){
selections['_' + record_id] = true;
// record was De-Selected
} else {
selections['_' + record_id] = false; //effectively removes key from hash
}
- If you want to get all the selected records
for(key in selection){
// remove underscore
var recordID = key.substr(1);
}
I think that there is an example of this in the “bugger” example solution.
Note, this might not update perfectly every time in Smart Client (scrolling foundsets).
Also, if you have a users table, then you can build a many-to-many resolver table for your user table to your images table.
i.e. ‘user_image_selections’ w/ fields ‘user_id’, ‘image_id’
Then your is_selected calculation can be based on a relation instead.
You get a persistent, user-specific selection. (Like selected messages in a gmail inbox)
This also obviates the need for an onDataChange event handler.
Hope this helps.
very nice trick but if I make a
selections[‘_myID’] = true
in another method, the GUI is not updated (the checkbox stay without tick)
and so I can’t make a “de/select all” method…
Right - Servoy will not see modifying the variable as a reason to rerun the calc/update the GUI
maybe try ```
controller.relookup()
...or maybe
databaseManager.recalculate(foundset)
To deselect all:
selections = new Object();
conroller.relookup(); // or dbmanager recalc?
// or dbmanager recalc?
to select all:
var ids = databaseManager.getFoundsetDataProviderAsArray(foundset, ‘id_field’)
for(i in ids){
selections[‘_’ + ids[i]] = true;
}
controller.relookup(); // or dbmanager recalc?
I read the documentation of relookup / recalculate but on either side these functions don’t do that.
I also try to apply them via script on a simply select_all function (copy your code) but either relookup / recalculate don’t update the checkbox tick…
I read the documentation of relookup / recalculate but on either side these functions don’t do that.
Recalculate does just what you need, recalculates the values of the foundset.
I also try to apply them via script on a simply select_all function (copy your code) but either relookup / recalculate don’t update the checkbox tick…
This code works for me:
selectAll:
var ids = databaseManager.getFoundSetDataProviderAsArray(foundset,'customerid');
for(i in ids){
globals.selections['_' + ids[i]] = true;
}
databaseManager.recalculate(foundset);
clearSelection
globals.selections = new Object();
databaseManager.recalculate(foundset);
Actually I did notice that there is a problem repainting after the selectAll() and the clearSelection() methods in foundsets that scroll
Adding an update UI call to the end seems to clear it up:
Note: This does NOT work in web client (updateUI is java specific)
i.e.
function selectNone()
{
globals.selections = new Object();
databaseManager.recalculate(foundset);
application.updateUI(0);
}
If you continue to have problems with this approach, then I suggest you go with a data driven approach. You can build a link table between a users table and the table in question and have the calculation be based on the presence of a related link record.
This approach is more “in-tune” w/ how Servoy works and wont have any refresh issues. It will also give your users a persistent selection.
Kind of like an email inbox where each time you log in, your selected messages stay the same.
hth,