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
Code: Copy
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
Code: Copy
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
 
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?
Code: Copy
jq.RunMethod("dataTable", Array As Object(CreateMap("aaData": data, "bFilter": False, _
        "bPaginate": True)))
 
Upvote 0
Philip,

try by adding
Code: Copy
"order":[]

Info from this link.

or

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

Am i sending the aaSorting correct?
 
Upvote 0
Philip,

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

Attachments

Upvote 0
Philip,

attached is an example. Disable sorting is set like:
Code: Copy
$(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
Code: Copy
jq.RunMethod("dataTable", Array As Object(CreateMap("bDestroy": True,"aaData": data, "bFilter": False, _
        "bPaginate": True,"bProcessing":True ,"aaSorting":"[[4,'asc']]")))
 
Upvote 0
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
Code: Copy
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

Upvote 0
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
Code: Copy
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 ;

Code: Copy
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
Philip,

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

Code: Copy
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

Upvote 0
Back
Top