0

Sorting for a View Element

I have a relation field with multiple records in it and I display it via a view element. Now I want to have some dynamic sorting by name, or by a number, but with the sorting I dont have some luck. Here is the code without the sorting and prepared for it.

let ActiveRecords := (select 'Line-up' where Zeitaufzeichnung.'Aufzeichnungen Meldung' like "recordings");
let ActiveRecordsbyName := ActiveRecords.Name;
let ActiveRecordsbyAmount := ActiveRecords.'Erarbeiteter Wert';
let AZ := ActiveRecords;
let ZA := ActiveRecords;
let Amount_UP := ActiveRecords;
let Amount_DOWN := ActiveRecords;
let WorkingInIt := ActiveRecords;
switch 'Sortierung Produktion' do
case 1:
    AZ
case 2:
    ZA
case 3:
    Amount_UP
case 4:
    Amount_DOWN
default:
    WorkingInIt
end

27 replies

null
    • John_Halls
    • 4 days ago
    • Reported - view

    Hi  

    I am fairly certain that the sort order is defined in the view (where you say which columns to show and you are able to sort one of them ascending or descending, not in the script that creates it.

    Regards John

      • Michael_Blechinger.1
      • 4 days ago
      • Reported - view

       I was thinking maybe its possible to make the sorting also dynamic, like you see here on the screenshot, how I intended it to get working.

      otherwise, I need to create 4 different views to have this sorting I need. But it's much more effort to get it done, than coding it. 

    • John_Halls
    • 4 days ago
    • Reported - view

     If it were me, I'd go with creating 4 views. You have done so much prep work anyway.

      • Michael_Blechinger.1
      • 4 days ago
      • Reported - view

       okay, so I will do that. With Ninext 3 it's a fun to duplicate now everything. I forgot about this nice extension. :-)

    • John_Halls
    • 4 days ago
    • Reported - view

    Of course, good luck!

    • Fred
    • 4 days ago
    • Reported - view

    Jacques has some good tips on ordering.

    So you could do something like:

    let ActiveRecords := (select 'Line-up' where Zeitaufzeichnung.'Aufzeichnungen Meldung' like "recordings");
    switch 'Sortierung Produktion' do
    case 1:
        ActiveRecords order by upper(Name)
    case 2:
        you will have to decide if you want to implement the global function
    case 3:
        ActiveRecords order by 'Erarbeiteter Wert'
    case 4:
        ActiveRecords order by -'Erarbeiteter Wert'
    default:
        ActiveRecords
    end
      • John_Halls
      • 4 days ago
      • Reported - view

      Hi Fred. I don't think the view takes into account how the records are sorted by the select. Let me know if that's incorrect.

      Regards John

      • Fred
      • 4 days ago
      • Reported - view

       You are correct. Sorry for spreading misinformation. 😢

    • Ninox partner
    • RoSoft_Steven.1
    • 4 days ago
    • Reported - view

    On the other hand, you could still use Fred's method if you replace the view with an HTML table in a formula field. Which is in my opinion much nicer than a regular view element...

      • John_Halls
      • 4 days ago
      • Reported - view

        Can you add links to these HTML tables that will go to a record? I've made cross-tabulation tables in HTML before but not had need to interact with them.

      Regards John

      • Ninox partner
      • RoSoft_Steven.1
      • 4 days ago
      • Reported - view

       

      Yes John, with the ui.popupRecord , you can popup the record...

      • Rafael Sanchis
      • Rafael_Sanchis
      • 3 days ago
      • Reported - view

       

      Something like that ? 

      • Michael_Blechinger.1
      • 3 days ago
      • Reported - view

       the way you did the UI is very impressive and lightweight. Can you give me some hints, how to do it like that? We can write separately from this forum.

      • Michael_Blechinger.1
      • 3 days ago
      • Reported - view

       Is there a instruction how to do it like you said?

      • Rafael Sanchis
      • Rafael_Sanchis
      • 3 days ago
      • Reported - view

       

      Why ui.popupRecord() works differently depending on context

      In a Table Page (form):

      onclick='ui.popupRecord("RECORD_ID")'

      ✅ Works because Ninox automatically knows which table you're working in (implicit context)

      In a Dashboard or Page without table context:

      onclick='ui.popupRecord("RECORD_ID")'

      ❌ Does NOT work because there's no defined table context

      onclick='ui.popupRecord("Table_Name", "RECORD_ID")'

      ✅ Works because you explicitly specify which table and which record to open

      General Rule:

      With table context → You only need the record ID

      Without table context → You need to specify TABLE + record ID

    • Ninox partner
    • RoSoft_Steven.1
    • 3 days ago
    • Reported - view

    I included an example database based on the Contacts template. If you look in the dashboard, you'll see the html-table.

     I also find it strange I cannot sort using the switch function so I had to use the if then loop... (see attachment) maybe you have any ideas?

     A click on the Contacts picture opens the record

      • Fred
      • 3 days ago
      • Reported - view

       This worked for me:

      let list := switch n do
          case 1:
              (me order by firstname)
          case 2:
              (me order by lastname)
          case 3:
              (me order by company)
          case 4:
              (me order by website)
          case 5:
              (me order by category)
          default:
              me
          end;
      

      See the video.

      • Ninox partner
      • RoSoft_Steven.1
      • 3 days ago
      • Reported - view

       Aha, this is of course a lot neater! thanks !

      I hadn't used the parentheses

      • Michael_Blechinger.1
      • 3 days ago
      • Reported - view

       Thank you very much, I will have a detailed look at it. :-)

      • Rafael Sanchis
      • Rafael_Sanchis
      • 2 days ago
      • Reported - view

       

      Hi Steven, What's happening if the Sorting Order Field is other, example Category a Chose Field in Contacts

      • Rafael Sanchis
      • Rafael_Sanchis
      • 2 days ago
      • Reported - view

      let list := switch n do

       case 1:

        (me order by category = "Family")

       case 2:

        (me order by category = "Business")

       case 3:

        (me order by stage = "Private")

       case 4:

        (me order by stage = "Other")

       default:

        me

       end;

      This work, The problem is order in desc mode 

      • Michael_Blechinger.1
      • 10 hrs ago
      • Reported - view

       For me it's not sorting the View Element. Does it work now or not?

      • Fred
      • 10 hrs ago
      • Reported - view

       Did you replace the View code with the one I posted?

      • Michael_Blechinger.1
      • 9 hrs ago
      • Reported - view

       yes this one:

      • Fred
      • 9 hrs ago
      • Reported - view

       Sorry, mis read your post.  is correct that you can't pre-sort views. If you see that my "working code" was for   's HTML table. 

Content aside

  • 9 hrs agoLast active
  • 27Replies
  • 81Views
  • 5 Following