Servoy 7 Conditional HTML in LIST or TABLE?

Using Servoy to administrate the content of your website? Discuss all webrelated Servoy topics on this forum!

Servoy 7 Conditional HTML in LIST or TABLE?

Postby bobcusick1332964082 » Wed Jun 26, 2013 9:56 pm

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.

I'm looking to do something like this:

Code: Select all
if(controller.getSelectedIndex() > 1) {
      return '<html><head></head><body><img src="media:///cross-button.png" border="0" width="16" height="16"></body></html>'
   } else {
      return null;
   }


I know that the onRender will work on formatting and the row/selected index color works in CSS... but this one has me at a loss.
bobcusick1332964082
 
Posts: 85
Joined: Wed Mar 28, 2012 9:48 pm

Re: Servoy 7 Conditional HTML in LIST or TABLE?

Postby peterbliskavka » Thu Jun 27, 2013 3:39 pm

You could probably use a global to get the selected index:


function getIndex() {
return forms.myForm.controller.getSelectedIndex();
}

and your calculation would look like:

if(globals.getIndex() > 1) {
return '<html><head></head><body><img src="media:///cross-button.png" border="0" width="16" height="16"></body></html>'
} else {
return null;
}
peterbliskavka
 
Posts: 30
Joined: Tue May 21, 2013 3:42 pm

Re: Servoy 7 Conditional HTML in LIST or TABLE?

Postby bobcusick1332964082 » Thu Jun 27, 2013 4:02 pm

Thanks, Peter!

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".

I appreciate the reply, though! :D

Bob
bobcusick1332964082
 
Posts: 85
Joined: Wed Mar 28, 2012 9:48 pm

Re: Servoy 7 Conditional HTML in LIST or TABLE?

Postby peterbliskavka » Thu Jun 27, 2013 5:22 pm

Heh, yeah now I can see how that wouldn't make much sense. What if you passed the pk of that record and did a lookup of its index?

you would call getIndex(rowPK) and getIndex would look more like:

function getIndex(pk) {
forms.myForm.foundset.selectRecord(pk);
return forms.myForm.foundset.getSelectedIndex();
}
peterbliskavka
 
Posts: 30
Joined: Tue May 21, 2013 3:42 pm

Re: Servoy 7 Conditional HTML in LIST or TABLE?

Postby bobcusick1332964082 » Thu Jun 27, 2013 5:30 pm

Again - thanks, Peter!

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). :D

Bob
bobcusick1332964082
 
Posts: 85
Joined: Wed Mar 28, 2012 9:48 pm

Re: Servoy 7 Conditional HTML in LIST or TABLE?

Postby peterbliskavka » Thu Jun 27, 2013 6:26 pm

selectRecord doesn't actually do what I thought it did. :oops:

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.
peterbliskavka
 
Posts: 30
Joined: Tue May 21, 2013 3:42 pm

Re: Servoy 7 Conditional HTML in LIST or TABLE?

Postby bobcusick1332964082 » Fri Jun 28, 2013 6:19 pm

Peter - no problem! I really appreciate you taking the "head time" to offer suggestions! :D

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).

Bob
bobcusick1332964082
 
Posts: 85
Joined: Wed Mar 28, 2012 9:48 pm

Re: Servoy 7 Conditional HTML in LIST or TABLE?

Postby ROCLASI » Sat Jun 29, 2013 11:21 am

Hi Bob,

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:
Code: Select all
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:
Code: Select all
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.

Hope this helps.
Robert Ivens
SAN Developer / Servoy Valued Professional / Servoy Certified Developer

ROCLASI Software Solutions / JBS Group, Partner
Mastodon: @roclasi
--
ServoyForge - Building Open Source Software.
PostgreSQL - The world's most advanced open source database.
User avatar
ROCLASI
Servoy Expert
 
Posts: 5438
Joined: Thu Oct 02, 2003 9:49 am
Location: Netherlands/Belgium

Re: Servoy 7 Conditional HTML in LIST or TABLE?

Postby david » Tue Jul 02, 2013 3:11 pm

Related to this thread, please vote up: https://support.servoy.com/browse/SVY-4775
David Workman, Kabootit

Image
Everything you need to build great apps with Servoy
User avatar
david
 
Posts: 1727
Joined: Thu Apr 24, 2003 4:18 pm
Location: Washington, D.C.

Re: Servoy 7 Conditional HTML in LIST or TABLE?

Postby ROCLASI » Tue Jul 02, 2013 3:40 pm

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.

Still something to vote for though.
Robert Ivens
SAN Developer / Servoy Valued Professional / Servoy Certified Developer

ROCLASI Software Solutions / JBS Group, Partner
Mastodon: @roclasi
--
ServoyForge - Building Open Source Software.
PostgreSQL - The world's most advanced open source database.
User avatar
ROCLASI
Servoy Expert
 
Posts: 5438
Joined: Thu Oct 02, 2003 9:49 am
Location: Netherlands/Belgium

Re: Servoy 7 Conditional HTML in LIST or TABLE?

Postby david » Tue Jul 02, 2013 4:45 pm

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...? :)

Thanks for the vote.
David Workman, Kabootit

Image
Everything you need to build great apps with Servoy
User avatar
david
 
Posts: 1727
Joined: Thu Apr 24, 2003 4:18 pm
Location: Washington, D.C.

Re: Servoy 7 Conditional HTML in LIST or TABLE?

Postby ROCLASI » Tue Jul 02, 2013 5:06 pm

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.
Robert Ivens
SAN Developer / Servoy Valued Professional / Servoy Certified Developer

ROCLASI Software Solutions / JBS Group, Partner
Mastodon: @roclasi
--
ServoyForge - Building Open Source Software.
PostgreSQL - The world's most advanced open source database.
User avatar
ROCLASI
Servoy Expert
 
Posts: 5438
Joined: Thu Oct 02, 2003 9:49 am
Location: Netherlands/Belgium

Re: Servoy 7 Conditional HTML in LIST or TABLE?

Postby david » Tue Jul 02, 2013 5:14 pm

Good one.
David Workman, Kabootit

Image
Everything you need to build great apps with Servoy
User avatar
david
 
Posts: 1727
Joined: Thu Apr 24, 2003 4:18 pm
Location: Washington, D.C.

Re: Servoy 7 Conditional HTML in LIST or TABLE?

Postby bobcusick1332964082 » Thu Jul 04, 2013 4:04 pm

Thanks very much guys!

It never ceases to amaze me how AWESOME this community is! Hopefully, in the future, it will be easier to do than go through all those gyrations... :shock:

Again - many thanks, guys! :D
bobcusick1332964082
 
Posts: 85
Joined: Wed Mar 28, 2012 9:48 pm

Re: Servoy 7 Conditional HTML in LIST or TABLE?

Postby jbrancoIF » Thu Jul 04, 2013 5:25 pm

I found another way
Code: Select all
return foundset && foundset.getSelectedIndex() > 1 ? '<html><head></head><body><img src="media:///cross-button.png" border="0" width="16" height="16"></body></html>' : null;

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.
João
InfoForm SA

Servoy 2021.03
jbrancoIF
 
Posts: 68
Joined: Tue Jan 10, 2012 11:29 am

Next

Return to Web Development

Who is online

Users browsing this forum: No registered users and 7 guests