1

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?

3
  • are you getting an error in the console? have you tried setting a breakpoint to see what the row argument looks like? Or a console.log? Commented Mar 9, 2018 at 19:56
  • Nothing shows in the error console, yet I am sure this is because "undefined" is getting passed which would not equal 1. Commented Mar 9, 2018 at 20:00
  • okay...the next step is to determine what "row" is. Sometimes it might be an array, but it can also be an object, in which case it might be row.DOCS_WAIT or something like that instead of row[6]. You really need to use either a debugger or a console log to make sure that row is what you think it is. You can also do a console.log(arguments) if it turns out row isn't actually the right argument for what you want Commented Mar 9, 2018 at 23:52

2 Answers 2

1

Thanks for all of your help.

Looks like the following code worked perfectly.

                     {
                    "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>';
                        }
Sign up to request clarification or add additional context in comments.

Comments

0

Use row['DOCS_VER'] to reference another property in the data set if your data is an array of objects.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.