Skip to content Skip to sidebar Skip to footer

How To Get The Progress Status In The "status" Column Of A Datatable Using Socket.io

I'm able to connect to socket and get the data .But I'm unable to display the percent in the status column. I'm getting this error : DataTables warning: table id=DataTables_Table_0

Solution 1:

Let's take a look here:

Each cell in DataTables requests data, and when DataTables tries to obtain data for a cell and is unable to do so, it will trigger a warning, telling you that data is not available where it was expected to be. The warning message is:

DataTables warning: table id={id} - Requested unknown parameter '{parameter}' for row `{row-index}, column{column-index}`` where:

{id} is replaced with the DOM id of the table that has triggered the error {parameter} is the name of the data parameter DataTables is requesting {row-index} is the DataTables internal row index (row().index()) for the row that has triggered the error. {column-index} is the column data index (column().index()) for the column that has triggered the error. The column index information was added in DataTables 1.10.10. So to break it down, DataTables has requested data for a given row, of the {parameter} provided and there is no data there, or it is null or undefined (DataTables doesn't know, by default how to display these parameters - see below if your data does contain these values).

You are getting this alert, because you are setting null value to mData property when you are building your databale. Here is described what happens when null is set as the value:

null - the sDefaultContent option will be used for the cell (null by default, so you will need to specify the default content you want - typically an empty string). This can be useful on generated columns such as edit / delete action columns.

So, to get rid of this alert you should set a sDefaultContent property:

aoColumns": [
      {
        "sTitle":"File Name", 
        "mData": null, 
        sDefaultContent: '',
        "bSortable": false, 
        "sClass": "head0", 
        "sWidth": "55px",
        "render": function (data, type, row, meta) {
          if (data.IsDirectory) {
            return "<a href='#' target='_blank'><i class='fa fa-folder'></i>&nbsp;"  + data.Name +"</a>";
          } else {
            return "<a href='/" + data.Path + "' target='_balnk'><i class='fa " + getFileIcon(data.Ext) + "'></i>&nbsp;" + data.Name +"</a>";
          }
        }
      },

Keep in mind that you should to it for every column.

PS: If you are using .emit() method to send data, you should pass an object as an argument. However, in the provided code you are passing a json string. if you want to send a string via socket, use .send() method:

io.of('/socket_issue').send('message', JSON.stringify({size: state.total, received: state.received, percent: state.percent, fileName: file_name}));

But I would advise you to pass an object:

io.of('/socket_issue').emit('message', {size:state.total, received:state.received, percent:state.percent, fileName:file_name});

In this case you should not use JSON.parse(data) on the front side, since it is not a string anymore. Change:

var percentage = JSON.parse(data).percent;

To:

var percentage = data.percent;

Post a Comment for "How To Get The Progress Status In The "status" Column Of A Datatable Using Socket.io"