4

add onselect event for view field

In response to Alain Fontaine  & Fred Christmas wish (https://forum.ninox.com/t/h7hbkmp?r=h7hbvzj), I have added a viewEvent function to Ninext project.

Just put viewEvent at true in an init code formula:

var configLoadModules := {
        completion: true,
        badges: true,
        evalJS: true,
        viewEvent: true
    };
html(http("GET", "https://raw.githubusercontent.com/JacquesTur/Ninext/main/loadModules.html").result);

This will be returned:

All that remains is to add the onselect() event function to the view field source formula:

The full code of the view field is :

function onselect(selectedID : text) do
    'Selected customer' := first(select Customer where ID = selectedID)
end;
select Customer

When you select a line in the field of view, the onselect function is called instead of the automatic event that displays a popup.

selectID represents the full (alphanumeric) id of the selected record. The context record this remains the owner record of the view field.

The second part (select Customer) is the standard initialization for the field of view content.

61 replies

null
    • Fred
    • 1 yr ago
    • Reported - view

    Hi all -

    Here is my setup. I have a dashboard, "All Horses Stats" that has a view element to a table called DashTemp. In DashTemp is a number field called HorseID.

    Now I want to click on a record in the view element but onclick to a table called Horses but use the data in HorseID in DashTemp to match a similar field in Horses. I can't use recordId as there is no relationship between the tables.

    I've tried:

    function onclick(event : any) do
        var selHorse := first(select Horses where HorseID = event.targetId.HorseID);
        popupRecord(selHorse);
        true
    end;
    

    and

    function onclick(event : any) do
        var selHorse := first(select Horses where HorseID = event.HorseID);
        popupRecord(selHorse);
        true
    end;
    

    Is there a way to access other field's data from the event. part or can do I only have access to the recordId?

    Thanks,

      • Fred
      • 1 yr ago
      • Reported - view

       that makes a lot of sense. thanks, Jacques

    • Patrick_W
    • 1 yr ago
    • Reported - view

     Hi Jacques,

    is it possible to deselect the selected line via script? When I click on a row, the row actually looks "selected". In my case, if I just want to trigger a true/false field like a checklist, I don't want to see a selected row.

    Maybe it's possible to show the overlay as a mouseover instead?

      • Ninox developper
      • Jacques_TUR
      • 1 yr ago
      • Reported - view

       I should be able to do this. You'll need to indicate in the return value of the onclick function that you don't want to select the line. For example, by returning a JSON of type { select : false }. I'll look into it soon. Thanks for your patience.

    • Icarus_Ralf_Becker
    • 7 mths ago
    • Reported - view

    This function doesn`t work since 3.12 anymore. I guess, it is in relation to Ninox bugfix of the blind view elements. Any hotfix possible?

      • Ninox developper
      • Jacques_TUR
      • 7 mths ago
      • Reported - view

       I saw your message last night. I will correct it as soon as possible. I think by tomorrow evening.

      • Ninox developper
      • Jacques_TUR
      • 7 mths ago
      • Reported - view

       It's fixed now

      • Icarus_Ralf_Becker
      • 7 mths ago
      • Reported - view

      awesome. Thank you

    • Icarus_Ralf_Becker
    • 3 mths ago
    • Reported - view

     I found out, that using this function causes a delay of 2 - 3 seconds, until the selected record appears in the popup. Do you it is possible to improve the popup speed like Ninext isn't used? Best regards, Ralf

      • Ninox developper
      • Jacques_TUR
      • 3 mths ago
      • Reported - view

       Generally, this function doesn’t introduce any noticeable delay, unless it contains code that requires significant execution time. Do you have a code snippet or an application example to share where selecting a line causes a noticeable delay?

      • Icarus_Ralf_Becker
      • 3 mths ago
      • Reported - view

       I doublechecked it after your reply and you are fully right. The delay was caused by a bad select statement I've overseen. 👍

    • Maurice
    • 3 mths ago
    • Reported - view

    Hello, my code in a view is

    function onclick(event : any) do
        let a := first(select Aufgaben where Nr = event.targetID);
        if event.targetColumnCaption = "Done" then
            a.(Check := not Check);
            true
        else
            void
        end
    end;
    

    But nothing happens. I checked several times if column name is "Done" and - of course - the view shows data with select Aufgaben.  In the table "Aufgaben" exists a yes/no field with name Check.

    I copied the code from another view where it works. I really have noch clue what makes the difference. When I click in the column "Done" the popup record opens instead to change the Check-field.

    Maurice

Content aside

  • 4 Likes
  • 3 mths agoLast active
  • 61Replies
  • 1672Views
  • 16 Following