B4J Question Websocket table order

Philip Prins

Active Member
Licensed User
Longtime User
I would like to order the displayed items in the table ,

tried
B4X:
FillAlarmsTable(tblAlarms, Main.db.ExecQuery2("SELECT NR,ID,Name ,Message,updated_time,Type  FROM Alarms WHERE Client = ? ORDER BY updated_time DESC", Array As String(ws.Session.GetAttribute("client"))))

Also tried
B4X:
jq.RunMethod("dataTable", Array As Object(CreateMap("aaData": data, "bFilter": False, _
        "bPaginate": True,"order": "[ 4, asc ]")))

But the order of displayed items will not change, any help is appreciated

Regards,
Philip
 

Philip Prins

Active Member
Licensed User
Longtime User
The database query order works ok ,the problem occurs when the data is send to the table, somehow the table orders it .
How can i send a order command to the jq run method?
B4X:
jq.RunMethod("dataTable", Array As Object(CreateMap("aaData": data, "bFilter": False, _
        "bPaginate": True)))
 
Upvote 0

rwblinn

Well-Known Member
Licensed User
Longtime User
Philip,

try by adding
B4X:
"order":[]

Info from this link.

or

B4X:
"aaSorting": []
 
Last edited:
Upvote 0

Philip Prins

Active Member
Licensed User
Longtime User
Philip,

try by adding
B4X:
"order":[]

Info from this link.

or

B4X:
"aaSorting": []
When i try order there is no difference, when i use aaSorting i get an empty table,
B4X:
jq.RunMethod("dataTable", Array As Object(CreateMap("aaData": data, "bFilter": False, _
        "bPaginate": True,"aaSorting":"[[4,'asc']")))

Am i sending the aaSorting correct?
 
Upvote 0

rwblinn

Well-Known Member
Licensed User
Longtime User
Philip,

attached is an example. Disable sorting is set like:
B4X:
$(document).ready(function() {
       $('#table1').dataTable( {
                "bProcessing":    true,
                "bPaginate":        false,
                "aaSorting": [],
                "sAjaxSource":    'TableHelper?method=show'
            } );
        });
 

Attachments

  • WebAppJQTableData.zip
    9.6 KB · Views: 194
Upvote 0

Philip Prins

Active Member
Licensed User
Longtime User
Philip,

attached is an example. Disable sorting is set like:
B4X:
$(document).ready(function() {
       $('#table1').dataTable( {
                "bProcessing":    true,
                "bPaginate":        false,
                "aaSorting": [],
                "sAjaxSource":    'TableHelper?method=show'
            } );
        });
Thanks ,this work but i am using the run method to update the table, if i add aaSorting the table remains empty
B4X:
jq.RunMethod("dataTable", Array As Object(CreateMap("bDestroy": True,"aaData": data, "bFilter": False, _
        "bPaginate": True,"bProcessing":True ,"aaSorting":"[[4,'asc']]")))
 
Upvote 0

rwblinn

Well-Known Member
Licensed User
Longtime User
Hi Philip,

without additional code hard to find out. Could you share your code - esp. where the jq.RunCommand is defined?

I have tried another way using WebSocket and the Eval Method (in index.html datatable statement taken out in the script section), like
B4X:
Dim dtu As String
dtu = "$(""#table1"").dataTable( {""bProcessing"":""True"",""bPaginate"":""False"", ""aaSorting"": []," & data & "} );"
ws.Eval(dtu, Null)
ws.Flush
with the same result = Order of the records as set by the Select command and NOT by the datatable. To note again, that data is string generated by the JSONgenerator (as in the first example)
Please find attached simple example.
 

Attachments

  • WebAppJQTableData2.zip
    10.9 KB · Views: 174
Upvote 0

Philip Prins

Active Member
Licensed User
Longtime User
Hi Philip,

without additional code hard to find out. Could you share your code - esp. where the jq.RunCommand is defined?

I have tried another way using WebSocket and the Eval Method (in index.html datatable statement taken out in the script section), like
B4X:
Dim dtu As String
dtu = "$(""#table1"").dataTable( {""bProcessing"":""True"",""bPaginate"":""False"", ""aaSorting"": []," & data & "} );"
ws.Eval(dtu, Null)
ws.Flush
with the same result = Order of the records as set by the Select command and NOT by the datatable. To note again, that data is string generated by the JSONgenerator (as in the first example)
Please find attached simple example.

Hello Rob,

The run method is defined in the javascript b4j_ws.js ;

B4X:
function b4j_connect(absolutePath) {
    if (typeof WebSocket === 'undefined') {
        window.alert("WebSockets are not supported by your browser.");
        return;
    }
    var l = window.location, fullpath;
    fullpath = ((l.protocol === "https:") ? "wss://" : "ws://") + l.hostname + ":" + l.port + absolutePath;
    b4j_ws = new WebSocket(fullpath);
    b4j_ws.onmessage = function (event) {
        var ed = JSON.parse(event.data);
        if (ed.etype === "runmethod") {
            $(ed.id)[ed.method].apply($(ed.id), ed.params);
        } else if (ed.etype === "runmethodWithResult") {
            b4j_sendData($(ed.id)[ed.method].apply($(ed.id), ed.params));
        } else if (ed.etype === "setAutomaticEvents") {
            b4j_addAutomaticEvents(ed.data);
        } else if (ed.etype === "runFunction") {
            b4j_runFunction(ed.prop, ed.value);
        } else if (ed.etype === "runFunctionWithResult") {
            b4j_sendData(b4j_runFunction(ed.prop, ed.value));
        } else if (ed.etype === "eval") {
            b4j_eval(ed.value, ed.prop);
        } else if (ed.etype === "evalWithResult") {
            b4j_sendData(b4j_eval(ed.value, ed.prop));
        } else if (ed.etype === "alert") {
            window.alert(ed.prop);
        }
       
    };
}
 
Upvote 0

rwblinn

Well-Known Member
Licensed User
Longtime User
Philip,

thx for sharing. Below a solution (attached is this example tested)

B4X:
Sub Class_Globals
    Private table1 As JQueryElement

...
    Dim m As Map
    m.Initialize
    m.Put("aaData", Main.DB.GetContacts)   
    m.Put("bFilter",False)
    m.Put("bPaginate": True)
    m.Put("bSort": False)
    table1.RunMethod("dataTable", Array As Object(m))
 

Attachments

  • WebAppJQTableData3.zip
    7.7 KB · Views: 187
Upvote 0
Top