Then I added a global variable filterProducts and made a global relation globals.filterProducts= products.product_category.
I created a form without any datasource and added one combobox containing the global variable filterProducts and a portal with the relation above.
Finally I added a valuelist with all product_categories to the filterProducts field.
When I now change the Categorie in the combobox the portal only shows products from this category.
And now my question - how can I show all topics/products ? My idea is that if nothing in the combobox is selected all products are shown and if a categorie is selected only products from this categorie are shown.
I atttached a small sample solution demonstrating the problem
The easiest way of doing that is not by using a global relation and a portal but by using a form based on the table you are filtering on (in table view mode) and a custom valuelist like this attached to a form variable in the form header:
function onShow()
{
if(arguments[0]) // only on first show
{
// Set up the selector valuelist
var _sql = "SELECT descr, cdsta FROM notstt1l WHERE cdling = ?"
var _ds = databaseManager.getDataSetByQuery('lfspa',_sql,[globals.gui_language],-1)
_ds.addRow(1,['-',null])
_ds.addRow(1,['Show All',99])
application.setValueListItems('totalization_status_selector', _ds)
}
}
and you have to trigger a method in onDataChange of the category selector to load the correct data in the tab panel form.
function onFilterChange()
{
var _new = arguments[1]
if(_new == 99)
{
// Load all the recs in the totalization table
var _sql = "SELECT codprj \
FROM nprevj0f \
WHERE codpre = ? AND magpro = ?"
controller.loadRecords(_sql,[forms.approvals_detail.codpre,forms.approvals_detail.magpro])
}
else
{
// Load all the recs in the totalization table with the selected status
var _sql = "SELECT codprj \
FROM nprevj0f \
WHERE codpre = ? AND magpro = ? AND statot = ?"
controller.loadRecords(_sql,[forms.approvals_detail.codpre,forms.approvals_detail.magpro,_new])
}
}
Keep in mind that the above code is running on Servoy 4.1 so if you use Servoy 5.x you have to handle the Event passed to every method attached to the GUI as arguments[0].
Hope this will help you get going and, by the way, welcome to the Servoy community
thanks for your provided solution. More or less I was able to reproduce your steps for filtering. But in my case there is still one problem.
So let me think about a solution where I have two forms representing the data of the same table products.
One form so called frmProducts which is used to manage the products.
One called lstProducts which is used for selecting some products and doing some Drag and Drop stuff.
So my problem now is if I do something like:
function onDataChangecbo_Product_Filter(oldValue, newValue, event) {
if (newValue != -1) {
var sqlstring = "SELECT product_id FROM products WHERE product_category = ?";
forms.lstProducts.controller.loadRecords(sqlstring, [newValue]);
} else {
var sqlstring = "SELECT product_id FROM products";
forms.lstProducts.controller.loadRecords(sqlstring, null);
}
}
The data in the form lstProducts is filtered nice but unfortunately the data in the other form frmProducts is also filtered which is not as expected/desired.
Any solutions on this ?
Regards
Steffen