Filtering from Pie Chart not working well with Custom filter.

To keep things simple, I’m using a PieChart to filter the results in a table. I’m doing it differently than Cuba expects. I use SliceClickListeners instead of OnSlicePullOut and OnSlicePullIn to adjust the query in the CollectionDatasource. A problem occurs when I have already adjusted the dataSource with the pie chart, then try to use the Custom Query I have created. What can I add to the custom query to fix this?

xml

 <collectionDatasource id="itemsDs"
                              class="company.entity.item.Item"
                              view="item-view">
            <query>
                <![CDATA[select e from edge$Item e]]>
                <filter>
                    <and>
                        <c>
                            <![CDATA[e.createTs >= :custom$startDate]]>
                        </c>
                        <c>
                            <![CDATA[e.createTs <= :custom$endDate]]>
                        </c>
                    </and>
                </filter>
            </query>
        </collectionDatasource>
...

<groupBox id="selectBetweenFilter"
                  collapsable="true"
                  collapsed="true"
                  caption="Select within range"
                  orientation="horizontal"
                  spacing="true">
            <hbox spacing="true">
                <label align="MIDDLE_LEFT"
                       value="Start date"/>
                <dateField id="filterStartDate"
                           dateFormat="MM/dd/yyyy"
                           resolution="DAY"/>
                <label align="MIDDLE_LEFT"
                       value="End date"/>
                <dateField id="filterEndDate"
                           dateFormat="MM/dd/yyyy"
                           resolution="DAY"/>
                <button id="applyFilterBtn"
                        caption="Apply"
                        invoke="applySelectBetweenFilter"/>
            </hbox>
        </groupBox>

And in ItemBrowse.java

    public void applySelectBetweenFilter() {
        Map<String, Object> params = new HashMap<>();
        Date startDate = filterStartDate.getValue();
        Date endDate = filterEndDate.getValue();

        if (startDate != null) {
            params.put("startDate", startDate);
        }
        if (endDate != null) {
            params.put("endDate", DateUtils.addDays(endDate, 1));
        }

        itemsDs.refresh(params);
    }

The problem is that the queries that are run after the pie chart changes don’t seem to do anything at all.

Hi,
I’ve checked your code and it works well. Could you attach whole problem screen with chart and give us steps to reproduce the issue ?

I could make the filter collapse, then refresh the entire page when it is reopened. That would be a quick-fix, but not the best solution.

What’s the best way to refresh the page?

querryProblemWithPieChart

If you change query using setQuery method, then QueryFilter tree with custom filter conditions will be set to null. To preserve the previous QueryFilter tree while changing Query, you can pass the previous QueryFilter to the setQuery method call:


public void changeQuery() {
    clientsDs.setQuery("select e from demo$Client e", clientsDs.getQueryFilter());
}

This issue is not related to charts it only affects data source query filter.

CUBA preserves UI state on refresh, so page refresh will not lead to reopening of a screen, and I wouldn’t recommend to workaround issues with UI logic using page refresh.

Beautiful! Thanks.