B4J Question [ABMaterial] [Solved] Sorting a table

JakeBullet70

Well-Known Member
Licensed User
Longtime User
Stupid question #49923 ;)

Trying to get the table sorting working. I have used the code from the ABMFeedback as a template but that seems not to be working right. What seems to be happening is both sorts are being used. First my ORDER BY sort and then the javascript sort seems to fire.

My SortChanged event is firing and I can change the ORDER BY clause.
If I rem out my SortChanged event the table is still sorting and I am assuming that is the javascript stuff.



1634029266067.png



1634029654211.png
 
Solution
Can you try it with this one? Make a copy of your existing sorttable.4.32.min.js file (or rename it) and copy the attached one. (it is in the www/js/ folder).

You may have to press CTRL+F5 in the browser to load the new one instead of a cached version.

JakeBullet70

Well-Known Member
Licensed User
Longtime User
OK, got some other issues sorted out (SqLite LIMIT is different the MySQL) so...
I have it working I think. But I believe a javascript event is firing for the grid sort. So here is what I did.

Rem'd out my sorting code ran the program, it is sorted on case_id and all looks good.
1634044107104.png


OK, so now I click on TITLE and the grid sorts.

1634044193753.png


So the grid has sorted itself even though I have no sorting code.

1634044338615.png


Now lets add my sort code back in and click on the title header.

1634044665336.png


2nd Click on the TITLE header.

1634044739887.png


So... I might be having a senior moment (I just retired) but it seems to me that there is a javascript sort going on if I have no sort code. My sort seems to be working
Anyway, is this working or should I just call it a career. LOL ;) Somedays I think I am getting to old for this. @alwaysbusy just wants me to go away... ;)
 
Upvote 0

JakeBullet70

Well-Known Member
Licensed User
Longtime User
I suspect with your sort code, something may not be ok in your queries. It looks weird to me that in one case Case ID starts with 103 and the second time with 108, while the sort is in both cases the same (A->Z).

That looked funny to me too. I had to redo the LIMIT clause as it was different then the MySQL one. I will play with the RAW SQL and see what is up with that. Thanks @alwaysbusy
 
Upvote 0

JakeBullet70

Well-Known Member
Licensed User
Longtime User
If you look at pic #2 (no sort code in the event) and the last pic the sort is the same. I pulled my SQL out and ran it in the Sqlite Admin and it is working fine.

Its like my sort is running but then the TABLE is running a javascript sort after.

Should the TABLE do any type of sort if I do not have anything in my sort_clicked event?


1634052732133.png
 
Upvote 0

JakeBullet70

Well-Known Member
Licensed User
Longtime User
I am getting a sort without any code in the tblCases_SortChanged event.

I have remmed out my SQL sort code and checked the last SQL statement to run and it is still set to sort by case_id but the table sorts by the title column.
In fact the table (without any code in the blCases_SortChanged ) will sort by what ever column I click.

Here is my code to define my table. What am I missing that is causing a javascript sort to fire? (I am assuming that is the issue)
B4X:
    '--- create a table
    Dim tblCases As ABMTable
    tblCases.IsResponsive = True
    tblCases.IsBordered = True
    
    ' IMPORTANT: we set usingQueriesToSort = true because we are going to handle the sorting, not the javascript sorting library
    ' When using Pagination, the sorting library does not know all the data SetColumnDataFields() is used when the 
    ' user clicks on a column head to sort to return in the SortChanged() event and the GetSortColumn() And SetSortColumn() methods.
    
    Dim txt1 As String = ABM.XTR(lang,"","UGRID20","Case ID")
    Dim txt2 As String  = ABM.XTR(lang,"","UGRID21","Project")
    Dim txt3 As String = ABM.XTR(lang,"","UGRID22","Item Type")
    Dim txt4 As String  = ABM.XTR(lang,"","UGRID23","Title")
    Dim txt5 As String  = ABM.XTR(lang,"","UGRID24","Priority")
    Dim txt6 As String  = ABM.XTR(lang,"","UGRID25","Status")
    Dim txt7 As String  = ABM.XTR(lang,"","UGRID26","Assigned To")
        
    Dim UsingQueriesToSort As Boolean = True
    Dim IsSortible As Boolean = True
    Dim IsInteractive As Boolean = True
        
    tblCases.Initialize(Page, "tblCases", IsSortible, UsingQueriesToSort, IsInteractive, "tbltheme")
    tblCases.SetHeaders(         Array As String (txt1            , txt2        , txt3,         txt4,        txt5,      txt6,           txt7))
    tblCases.SetHeaderThemes(    Array As String ("bg"              ,"bg"       , "bg"         ,"bg"        , "bg"    , "bg"          , "bg"))
    tblCases.SetHeaderHeights(   Array As Int    (   0              , 0         , 0             , 0           , 0       , 0            ,0 ))
    tblCases.SetColumnVisible(   Array As Boolean(True,            True       , True         , True        , True      , True           ,True))
    tblCases.SetColumnSortable(  Array As Boolean(True,            True      , True          , True        , True      , True          , True))
    tblCases.SetColumnDataFields(Array As String ("case_id",     "project",  "item_type",     "title",    "priority", "workflow_step"  ,"assigned_to"))
    tblCases.SetColumnWidths(     Array As Int   ( 90 ,             180 ,       100,            480,          100          , 100            ,110))
    tblCases.SetFooter(ABM.XTR(lang,"","UGRID06","Total number of records:") &  " 0",  12,"bg")
    Page.CellR(1,1).AddComponent(tblCases)
    MaxRows = gbl.CalcTableSize(Page,MaxRows)     '--- calcs table size
    'ABMShared.ConnectFooterFixed(Page)  '--- footer on bottom
    LoadCases(1)
 
Upvote 0

JakeBullet70

Well-Known Member
Licensed User
Longtime User
Same issue with the sample app. There is a javascript sort firing after the DB sort.
In fact you can stop B4J and the sort is still firing locally in the browser. (but only in ASC order)

Only thing I changed in this app was the connection to an MariaDB



1634117904458.png
 
Upvote 0

alwaysbusy

Expert
Licensed User
Longtime User
Can you try it with this one? Make a copy of your existing sorttable.4.32.min.js file (or rename it) and copy the attached one. (it is in the www/js/ folder).

You may have to press CTRL+F5 in the browser to load the new one instead of a cached version.
 

Attachments

  • sorttable.4.32.min.zip
    4.8 KB · Views: 194
Upvote 0
Solution
Top