Using javascript datasource and created row

Using javascript datasource and created row

MadBoyEvoMadBoyEvo Posts: 119Questions: 38Answers: 0

I use following code to highlight field based on data. This works as long as datasource is HTML.

"createdRow": function (row, data, dataIndex, column) {
    if (data[5] == 'False') {
        $(column[5]).css({
            "background-color": "#ff0000"
        });
    }
}

But if I define datasource inside JS (for performance reasons) things are not working. Is there a workaround?

This question has an accepted answers - jump to answer

Answers

  • kthorngrenkthorngren Posts: 20,378Questions: 26Answers: 4,781

    things are not working.

    What things exactly? What happens.. Do you get errors in the browser's console?

    Kevin

  • MadBoyEvoMadBoyEvo Posts: 119Questions: 38Answers: 0

    No, just nothing happens. It seems when JavaScript source is used:

        "rowCallback": function (row, data) {
            if (data.HandleCount > 300) {
                $('td:eq(21)', row).css({
                    "background-color": "#ffff00"
                })
            } if (data.ID > 16000) {
                $('td:eq(22)', row).css({
                    "background-color": "#008000"
                })
            } if (data.Name == 'browser_broker') {
                $('td', row).css({
                    "background-color": "#ffd700"
                })
            }
        }
    
  • MadBoyEvoMadBoyEvo Posts: 119Questions: 38Answers: 0

    So the above works. So it would seem depending if it's HTML source or JavaScript source I need to apply different approach.

  • MadBoyEvoMadBoyEvo Posts: 119Questions: 38Answers: 0
    edited August 2020

    Ok, I was wrong. If I just change data[5] to data.ColumnName it works - so it seems it's just matter of how I handle data comparison.

    Edit:
    Or I thought it works, but now that I test it - not so much

  • MadBoyEvoMadBoyEvo Posts: 119Questions: 38Answers: 0

    But it's enough for me to have different calls - rowcallback for JavaScript source and createdRow for HTML. Thank you.

  • kthorngrenkthorngren Posts: 20,378Questions: 26Answers: 4,781
    Answer ✓

    The difference is whether you are using array data or object data. If you define columns.data you are using object data and need to access using object notation such as data.HandleCount instead of data[5]. createdRow will work with either DOM sourced data or Javascript sourced data.

    Kevin

This discussion has been closed.