I'm using SmartClient_v121p_2020-04-14_PowerEdition. I have a ListGrid backed by a "clientOnly" DataSource. I also have a FilterBuilder component that is used to filter the ListGrid. After the user enters the desired criteria and clicks my "Apply Filter" button, I filter the ListGrid as such:
This works as designed and my grid is filtered appropriately. Once the data is filtered, I need to use the filtered data to perform another function in the application. I need to make sure the filterData operation is complete before actually trying to retrieve the filtered data to use in the other function. According to the documentation, you can add in a callback:
So, I changed the code to this:
I see that it says that the callback will only fire if server contact was required, but I am not sure what is actually happening in this case as the callback is not being fired. I thought that invoking the filterData function on the ListGrid would use the underlying DataSource to filter the data, which would count as "server contact" regardless of whether or not it's a clientOnly DataSource. But, I am sure I'm misunderstanding how this is working. I also saw this in the fetchData() documentation:
I don't know that calling invalidateCache() is really what I should be doing. So my question is, how do I ensure that the filterData operation is complete since I don't think I can rely on the callback? Thanks in advance for your help.
Code:
const criteria = filterBuilder.getCriteria(); listGrid.filterData(criteria);
callback (optional) - type: DSCallback
callback to invoke when a fetch is complete. Fires only if server contact was required; see fetchData() for details
callback to invoke when a fetch is complete. Fires only if server contact was required; see fetchData() for details
Code:
listGrid.filterData(criteria, function(dsResponse, data, dsRequest) { // DO SOMETHING HERE });
Changes to criteria may or may not result in a DSRequest to the server due to client-side filtering. You can call willFetchData(criteria) to determine if new criteria will result in a server fetch.
If you need to force data to be re-fetched, you can call invalidateCache() and new data will automatically be fetched from the server using the current criteria and sort direction. NOTE: when using invalidateCache() there is no need to also call fetchData() and in fact this could produce unexpected results.
If you need to force data to be re-fetched, you can call invalidateCache() and new data will automatically be fetched from the server using the current criteria and sort direction. NOTE: when using invalidateCache() there is no need to also call fetchData() and in fact this could produce unexpected results.
Comment