Is it possible to populate different checkboxes from a query?

Hello!

To filter a table a need multiple filters array, I would need checkboxes so visually I can tell wich one is selected or not. It´s possible to populate different checkboxes from a single query?

For example if I got a query with [ACC,PRF,PRL,PRR,Z1,Z2...]

Do you have a single query that can get all your data points? Something like

SELECT
    ACC,
    PRF,
    PRL,
    #rest of columns
FROM someTable

?

If so,I would put that in a custom proprety somewhere, or a session prop if this is used all over your project, and then you can use try({path.to.dataset},[0, 'ACC'], False) where 0 is the row number (Assuming you can get this all in one row), 'ACC' is the column name, and False represents a fallback value you don't get anything, to get the value out of that dataset. Bind it to the selected prop.

2 Likes

The query is :

SELECT DISTINCT
CASE 
WHEN A.COMPANYLEVEL=5 THEN SUBSTR(WO.ASSET,11)
WHEN A.COMPANYLEVEL > 5 THEN SUBSTR((SELECT APA.PARENTASSET FROM ASSETPARENTASSET APA INNER JOIN ASSET B ON 
APA.COMPANY=B.COMPANY AND APA.PARENTASSET=B.ASSET WHERE APA.COMPANY=WO.COMPANY AND APA.ASSET=WO.ASSET AND 
A.COMPANYLEVEL=5),11)
ELSE N'SD' END AS FAMILIA,0 AS INCLUDED

FROM WORKORDER WO INNER JOIN ASSET A ON WO.COMPANY=A.COMPANY AND WO.ASSET=A.ASSET
WHERE WO.COMPANY='TIENDAS'
ORDER BY FAMILIA

I learnt this from Transistor.

with the result [ACC,PRF,PRL,PRR,Z1,Z2...]

then will need to filter a table based on the correspondent checkboxes

I will do a custom property with a expression structure
image

and the script transform like:


    selected_work_types = []

    # Check each work type checkbox and append corresponding value if selected
    if value['listWorkType_ACC']:
        selected_work_types.append('ACC')
    if value['listWorkType_PRF']:
        selected_work_types.append('PRF')
    if value['listWorkType_PRL']:
        selected_work_types.append('PRL')
    if value['listWorkType_PRR']:
        selected_work_types.append('PRR')
    if value['listWorkType_Z1']:
        selected_work_types.append('Z1')
    if value['listWorkType_Z2']:
        selected_work_types.append('Z2')
    if value['listWorkType_Z3']:
        selected_work_types.append('Z3')
    if value['listWorkType_Z4']:
        selected_work_types.append('Z4')
    if value['listWorkType_Z5']:
        selected_work_types.append('Z5')

    # Return a comma-separated string of selected work types, or None if none are selected
    return ','.join(selected_work_types) if selected_work_types else None

the problem is that i would like to get the checkboxes values from the query and not fixed

If you have the data in a dataset somewhere you can just bind the checkbox with an expression to the selected record and field

{../Table.props.selection.data[0].ACC}

2 Likes

Ok, thank you all, will try, coming back if I have some issue!

This sub query here will make your query slow. It also likely depends on it returning only a single value. I would see if you can merge this into the main query instead, otherwise that query will be run for every single row that's returned. I would also format the whole query to be more readible for future you and future other people

1 Like