B4J Tutorial [ABMaterial] Number of Data Grid Rows to Display

I work on a laptop (14" screen) as my primary screen.
I also have a 21 inch screen as my extended display (used for browser display mostly).

The Feedback example hard-coded the number of table rows to 10 (Fine for most situations).
However, when I view the same grid on my laptop, I must scroll to see the entire grid of rows.

I could introduce some JS code that returns the screen height so I could programmaticly determine how many rows to display, but that is way above my current skill level with AMB...

I replaced the hard coded value of 10 with a Private var of iRecs (default 10).

I also created a FixedFooter to use as a toolbar (as suggested by alwaysbusy).
Within the footer, I added the ability to add a new record, adjust the row height and select a page of records. I hope to make this common to my theme.

The UP and DOWN controls of the Grid Rows increase or decrease the number of rows to display.
Each time either control is clicked, a call to LoadCases(1) is made.

B4X:
'  in Class_Globals
Private iRecs As Int = 10

   ' in  Sub LoadCases(fromPage As Int)   
   '  SQL_str =
     & " LIMIT " & ((fromPage - 1) * iRecs) & ", "&iRecs

   'at end of sub...

   If (numcases mod iRecs > 0) Or (numcases = 0) Then
       numcases = numcases/iRecs + 1
   Else
       numcases = numcases/iRecs
   End If

'  End Sub

The More and Less button clicks...
B4X:
Sub MoreBtn_Clicked(Target As String)

  iRecs = iRecs + 1
  LoadCases(1)
  Log(" Irecs: "&iRecs)
End Sub


Sub LessBtn_Clicked(Target As String)
  iRecs = iRecs - 1
  If iRecs < 2 Then
      iRecs = 2
  End If
  LoadCases(1)
  Log(" Irecs: "&iRecs)
End Sub

More....
ABMFeedback3.png


Less....
ABMFeedback4.png
 

Harris

Expert
Licensed User
Longtime User
Added Saving user selected number of grid rows to Users table - using the UserActive field as an experiment.
This way each user won't have to constantly adjust row size every time he/she enters the page.
B4X:
Sub UpdateUserRows()

    Dim sql As SQL = DBM.GetSQL
    DBM.SQLUpdate(sql,"UPDATE Users SET UserActive = "&iRecs&" WHERE UserID = "&UserID)
    DBM.CloseSQL(sql)
   
End Sub

In the Private Sub WebSocket_Connected (WebSocket1 As WebSocket), I set the row size to user preference or default it to 10
B4X:
    UserRows = page.ws.Session.GetAttribute2("UserActive", "0")

    Dim SQL As SQL = DBM.GetSQL
    Dim users As List = DBM.SQLSelect(SQL, "SELECT UserName, UserActive FROM Users WHERE userId=" & UserID)
    If users.Size > 0 Then
        Dim user As Map = users.Get(0)
        UserName = user.GetDefault("username", "")
        UserRows = user.GetDefault("useractive", 10)
        If UserRows > 0 Then
           iRecs = UserRows
        Else
           iRecs = 10
        End If         
    End If
       
    DBM.CloseSQL(SQL)
 
Top