I know that I’m definitely getting older - as I know that there is a way to do this - but can’t quite seem to figure it out…
I have either a LIST or TABLE - and I want to conditionally show a button based on whether or not the current record is the first one - using a HTML calculation.
In the “old days” - you could just reference the controller.getSelectedIndex() and then if it was not the first row, then return some HTML, if it was - then return null.
However, since 7.x “tightened up” access to objects in the calc engine - it doesn’t seem to work.
However, it won’t work. The reason is that is has no context - so you get the last number that the controller drew. So if you have 10 records - then the result (for each row) is “10”. If you have 2 rows, then they all evaluate to “2”.
However, this will ALWAYS return “1” - since you are telling the foundset to go to that row, and then get the number of the row in that foundset (which is always 1).
selectRecord doesn’t actually do what I thought it did.
If you don’t have to use an HTML calculation, you can put a method on onRecordSelection that does the check for you then hides/shows the button. But beyond that, I am not sure how else to accomplish this. Sorry I couldn’t be of more help Bob.
Peter - no problem! I really appreciate you taking the “head time” to offer suggestions!
It does need to be a HTML calculation - because I want to conditionally show a graphic. The way list/tableview works is only one “model” is created for every row. If you “hide” a field - it’s hidden for the entire list/table, not just a single row. If you use the calculation workaround - then you can conditionally make a graphic “appear” on selected rows (as long as the calculation is based on some other criteria than the number of the current record in the foundset).
I think you need to use the onRender method for this in combination with a in-memory column (calc that returns itself).
Create an un-stored calc like so:
function c_myBtn() {
return; // this will make it an in-memory column
}
Now go to your form and place a label on the body form-part and lets say we name it ‘lblBtn’ and add the calc as a data provider.
Then add the following onRender method to the onRender form event:
function onRender(event) {
// check if we are rendering the field/label we want to render
if (event.getRenderable().getName() == 'lblBtn') {
var _rc = event.getRecord();
// reset the value in the in-memory column
_rc[event.getRenderable().getDataProviderID()] = '';
if (event.isRecordSelected() && event.getRecordIndex() > 1) {
// selected record is not the first row
_rc[event.getRenderable().getDataProviderID()] = '<html><head></head><body><img src="media:///cross-button.png" border="0" width="16" height="16"></body></html>';
}
}
}
This will then draw the cross-button on the selected row for all but the first row.
I don’t see how that issue of hiding/showing a whole column is in anyway related to getting a calculation to produce HTML depending on the selected record.
Ah yea, you are correct. Well, here’s an onRender related ticket we have open as well: https://support.servoy.com/browse/SVY-4729. Also not very related but if you put both together…?
onRender is very problematic indeed. I also filed an issue for it. It’s being worked on as we speak (at least it’s marked as in-progress). https://support.servoy.com/browse/SVY-4757
Lets hope this will then fix some other (perhaps) related issues as well.
Only problem is you need a databaseManager.recalculate(foundset); in the onRecordSelection, so maybe it’s not a very good idea.
It shows a warning when using foundset inside the calculation, but it works.
ROCLASI:
onRender is very problematic indeed. I also filed an issue for it. It’s being worked on as we speak (at least it’s marked as in-progress). https://support.servoy.com/browse/SVY-4757
Lets hope this will then fix some other (perhaps) related issues as well.
FYI, a fix was committed today to trunk (7.2) and 6.1.x