2021.08.06 05:03 AM - edited 2021.08.06 09:35 PM
I created a virtual query which clears some view states and set it as data source for an action. It works as expected when action is triggered but I found out that it is also executed at page load. If I pass parameters to the dashboard they are now cleared because of this side effect.
How do I make sure that the query is only triggered by an action?
Here's the query:
2021.08.10 06:34 AM - edited 2021.08.10 06:35 AM
Hi Nick,
Using the following as an example:
When I come to the dashboard, the text viewstate is present. There is a virtual query however it does not wipe this viewstate.
When I press clear, it activates the viewstate and clears the text.
If I refresh the screen, the default text "Hello World" is present:
or if I click reset text it will add "Hello World (again):
Button Actions
Virtual query
Result
Output mapping
Unfortunately I'm not able to attach json (example dashboard) on the Community portal yet, however I'll drop you an email to see if it helps solve your issue.
Kind regards,
David
---
Virtual Query
function (source, enabled, callback) {
var result = {
meta: {
k:11,
v:11
},
columns: [
"k",
"v"
],
rows: []
};
if(enabled) {
console.log('Clearing viewstates');
result.rows = [
{k:'text', v:null},
{k:'triggerEnabled', v:false}
];
} else {
console.log('Returning current');
result.rows= [
{k:'text', v:source},
{k:'triggerEnabled', v:enabled}
];
}
callback(result);
}
2021.08.07 09:21 PM - edited 2021.08.10 03:41 AM
Hi Nick,
You could try passing in a boolean viewstate triggerEnabled to your virtual datasource, which has a default value as false when the page loads to prevent it clearing.
Something like:
function (x, triggerEnabled, callback){
if(!triggerEnabled) {
callback(x) // i.e. just return x without modifying
}
else {
callback ({
// i.e. your custom clear logic
});
}
}
Set the viewstate to true when you actually want to clear the viewstates.
You can also map an output viewstate to reset the triggerEnabled viewstate to false after execution.
Hope this helps!
Cheers,
David
2021.08.09 11:08 PM
Hi David,
Thanks for reply. However I don't think this solution will work as the fact of setting triggerEnabled to true will trigger the query, giving similar side effect.
2021.08.10 03:43 AM
Hi Nick,
I've updated the skeleton to make it a little clearer. When the page first loads, this virtual query will run but will not clear your parameters if you return the input without modifying.
It should only run the clear logic when you set the triggerEnabled to true (intentionally).
2021.08.10 04:06 AM
How do I set triggerEnabled from an action (e.g. click on a cell in a data grid)? Isn’t that the same problem as setting the original view state to null?
2021.08.10 06:34 AM - edited 2021.08.10 06:35 AM
Hi Nick,
Using the following as an example:
When I come to the dashboard, the text viewstate is present. There is a virtual query however it does not wipe this viewstate.
When I press clear, it activates the viewstate and clears the text.
If I refresh the screen, the default text "Hello World" is present:
or if I click reset text it will add "Hello World (again):
Button Actions
Virtual query
Result
Output mapping
Unfortunately I'm not able to attach json (example dashboard) on the Community portal yet, however I'll drop you an email to see if it helps solve your issue.
Kind regards,
David
---
Virtual Query
function (source, enabled, callback) {
var result = {
meta: {
k:11,
v:11
},
columns: [
"k",
"v"
],
rows: []
};
if(enabled) {
console.log('Clearing viewstates');
result.rows = [
{k:'text', v:null},
{k:'triggerEnabled', v:false}
];
} else {
console.log('Returning current');
result.rows= [
{k:'text', v:source},
{k:'triggerEnabled', v:enabled}
];
}
callback(result);
}
2021.08.11 03:26 AM
Thanks David, I got it working now. I was confused at first as there's no way to set a view state to a value in an action for a DataGrid, it can only copy from a cell. I adapted your solution and used the Row Id column instead of 'true', so in my case triggerEnabled is a string, not a boolean.
EMEA
Tel: +44 (0)28 3025 2242
AMERICAS
Tel: +1 (212) 447 6700
APAC
Tel: +61 (0)2 9236 5700
KX. All Rights Reserved.
KX and kdb+ are registered trademarks of KX Systems, Inc., a subsidiary of FD Technologies plc.