Python Forum
Flask.socketio and client side html tables / JS
Thread Rating:
  • 2 Vote(s) - 2 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Flask.socketio and client side html tables / JS
#2
Please guys, some help

Below is some of my python code and associated Javascript in html

battling to print tot_cnt, cnt and the data array to a html table.

# app.py
# Background process to update the Delivery data

def background_thread_eft_del():

    while True:
        socketio.sleep(10)
        timeC = time.strftime('%Y/%m/%d %H:%M:%S')

        # Dummy data, to be replaced by Oracle_CX DB queries
        delivery        = {'cnt': 2, 'tot_cnt': 40, 'ds': [['row1',4,9], ['row2',6,2], ['row3',20,98], ['row4',4,9], ['row5',6,0]] }

        delivery_json   = json.dumps(delivery)

        socketio.emit('eft_delivery_update', {'timeC': timeC, 'delivery': delivery_json, 'debug_level': debug_level}, namespace='/eft')


#and the JS code and associated html 
#dashboard.html

[html]
 // Lets update the Delivery table
                socket.on('eft_delivery_update', function(msg) {

                    var timeC               = msg.timeC
                    var debug_level         = msg.debug_level

                    var delivery            = msg.delivery
                    var delivery_cnt        = msg.delivery.cnt
                    var delivery_tot_cnt    = msg.delivery.tot_cnt

                    if (debug_level > 0) {
                        console.log(delivery)
                    }

                    $('#timeC').text( timeC );

                    $('#delivery_cnt').text( delivery_cnt );
                    $('#delivery_tot_cnt').text( delivery_tot_cnt );

                    $('#delivery').append('<tr><td>' + $('<div/>').text( delivery ).html() );

                });

        <table id="EFT_Verticals">
            <th><h2>Delivery: <span id="del_cnt"></span>/<span id="del_tot_cnt"></span></h2></th>
            <th><h2>Load: <span id="load_cnt"></span>/<span id="load_tot_cnt"></span></h2></th>
            <th><h2>Validate: <span id="validate_cnt"></span>/<span id="validate_tot_cnt"></span></h2></th>
            <th><h2>Rec Completed: <span id="rec_compl_tot_cnt"></span></h2></th>
            <tr>
                <td valign="top">
                    <table border="1" id="delivery">
                    </table>
                </td>
                <td valign="top">
[/html]
G
Reply


Messages In This Thread
RE: Flask.socketio and client side html tables / JS - by georgelza - Jun-05-2018, 03:56 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  python socketio-client-2 and nod js socketio server communication is not success vmyadhu2 2 6,640 Oct-02-2017, 04:22 AM
Last Post: vmyadhu2

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020