jQuery DataTables: comparing two columns

时间:2018-03-09 19:13:51

标签: javascript jquery datatables

I'm running the latest version of the jQuery DataTables and using the server side option. I'm running into a problem when trying to complete a simple compare of two columns of data.
This DOCS_VER value in column 5 below will contain a 0 or a 1:

{ "data": "DOCS_VER" },

And the DOCS_WAIT database value in column 6 will contain some kind of text like "Refered" which comes from the database.

{ "data": "DOCS_WAIT" },

My rendering script is shown below and runs only without the else if option. I cannot figure out how to add the additional check for the DOCS_WAIT option.

{
  "targets": -4,
  "data": "DOCS_VER",
  "render": function (data, type, row) {
    var color = 'black';
    if (data == 1) {
      color = 'green';
      ColorCheck = 'VALIDATED';
      IconChoice = ' fa fa-check-square-o';
    } else if (row[6] == 1) {
      color = 'orange';
      ColorCheck = 'WAITING';
      IconChoice = 'fa fa-spin fa-spinner';
    } else {
      color = 'red';
      ColorCheck = 'NON-VALID';
      IconChoice = 'fa fa-exclamation-triangle';
    }
    return '<span style="color: ' + color + '"><i class="' + IconChoice + '"></i> ' + ColorCheck+ '</span>';
  },
},

Anyone have any ideas how to properly check row 6 to see if it's a 1 or 0?

2 个答案:

答案 0 :(得分:1)

感谢您的所有帮助。

看起来以下代码完美无缺。

                     {
                    "targets": -4,                          
                    "render": function ( data, type, row )
                        {
                            var color = 'black';
                            if (row['DOCS_VER'] == 1) {
                            color = 'green';
                            ColorCheck = 'VALIDATED';
                            IconChoice = ' fa fa-check-square-o';
                        } 
                            else if (row['DOCS_WAIT'] == 1) {
                            color = 'orange';
                            ColorCheck = 'WAITING';
                            IconChoice = 'fa fa-spin fa-spinner';
                        } 
                            else  {
                            color = 'red';
                            ColorCheck = 'NON-VALID';
                            IconChoice = 'fa fa-exclamation-triangle';
                        }

                        return '<span style="color:' + color + '"><i class="' + IconChoice + '"></i> ' + ColorCheck+ '</span>';
                        }

答案 1 :(得分:0)

如果您的数据是对象数组,请使用row['DOCS_VER']引用数据集中的其他属性。