NetTalk Central

Author Topic: Javascript filter of a browse  (Read 6749 times)

Rene Simons

  • Hero Member
  • *****
  • Posts: 650
    • View Profile
Javascript filter of a browse
« on: September 28, 2019, 01:39:42 AM »
Hi,

When building a browse for e.g. a phone app, the filtering is to be client side.
In the documentation an example shows a javascript statement like

'return record.paid ==1 ? recordOk : recordFiltered'

2 questions:
  • Has this condition/statement to be quoted?
  • Is it possible/allowed to call a javascript function here (with parms) which returns the recordOk or recordFiltered value?
Rene
Rene Simons
NT14.14

DonRidley

  • Don Ridley
  • Global Moderator
  • Hero Member
  • *****
  • Posts: 729
  • donaldridley2011@gmail.com
    • View Profile
    • Email
Re: Javascript filter of a browse
« Reply #1 on: September 30, 2019, 02:02:15 AM »
Hello Rene,

Quoted in the JS itself?  No.

I'm not a JS expert but I'm fairly sure you could call a function and get that return value. 

Don
"Eliminate the impossible, whatever remains, however unlikely, must be the truth."

NetTalk 12.55
Clarion 11

Rene Simons

  • Hero Member
  • *****
  • Posts: 650
    • View Profile
Re: Javascript filter of a browse
« Reply #2 on: September 30, 2019, 03:20:06 AM »
Hi Don,

Thanks for your reply.
ad 1: That would be nice in case you have a more complicated (but not too complicated) filter.
ad 2: I mean in the template field where the JS-filter must be typed in.

René
Rene Simons
NT14.14

DonRidley

  • Don Ridley
  • Global Moderator
  • Hero Member
  • *****
  • Posts: 729
  • donaldridley2011@gmail.com
    • View Profile
    • Email
Re: Javascript filter of a browse
« Reply #3 on: September 30, 2019, 05:42:53 AM »
ad 2: I mean in the template field where the JS-filter must be typed in.

Yes sir.  That needs to be in quotes. 
"Eliminate the impossible, whatever remains, however unlikely, must be the truth."

NetTalk 12.55
Clarion 11

Bruce

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 11250
    • View Profile
Re: Javascript filter of a browse
« Reply #4 on: October 09, 2019, 02:41:44 AM »
Hi Rene,

yes, you can call a JavaScript function here. The function should return RecordOk or RecordFiltered.

here's an example from the CIDC training app;

function filterMessages(){
   if ( (database.messages.record.fromuserguid == database.friends.record.friendguid) ||
       (database.messages.record.touserguid == database.friends.record.friendguid) ){
      return recordOk
   } else {
      return recordFiltered
   }   
};


Cheers
Bruce

Rene Simons

  • Hero Member
  • *****
  • Posts: 650
    • View Profile
Re: Javascript filter of a browse
« Reply #5 on: October 09, 2019, 05:25:43 AM »
Bruce,

Nice! Thank you.

René
Rene Simons
NT14.14