简体   繁体   中英

JavaScript - Colour a row on a table depending on a value of a cell

I need a bit of help from any of the coders out there.....

Currently, the code Reads which a CSV file and then outputs it to a html file using Powershell. And I have to use Powershell as there are other bits to this code(not shown here) which uses Powershell.

How do you colour a row on a table depending on a value of a cell?

Current bit of code look as below.


$datagridView1.DataSource | Export-Csv c:\tmp\test.csv

#HTML OUTPUT   

$head= @"
<style>
BODY{background-color:white;}
TABLE{border-width: 3px;border-style: solid; border-color:white;border-collapse:
collapse;}
TH{border-width: 3px;padding: 2px;border-style: solid;border-color: white;background-     color:yellow}


</style>

<script type="text/javascript">
    var allText =[];
    var allTextLines = [];
    var Lines = [];

    var txtFile = new XMLHttpRequest();
    txtFile.open("GET", "file://c:/tmp/test.csv", true);
    txtFile.onreadystatechange = function()
    {
        allText = txtFile.responseText;
        allTextLines = allText.split(/\r\n|\n/);
    };

    document.write(allTextLines);<br>
    document.write(allText);<br>
    document.write(txtFile);<br>
</script>
"@
$datagridView1.DataSource | convertto-html -head $head –body "<H2>Query</H2>" | Out-File         C:\tmp\app.html

The app.html file also seems to be creating the following four columns which are not in the CSV file (RowError, RowState, Table, ItemArray, HasErrors) and I can't figure out where its coming from.

Any help would be greatly appreciated

The following would make any table background a color of blue if the table data has a value of 3:

$("td:contains('3')").css({'background-color':'blue'});

jQuery is an amazing tool for simplifying your code. Though JavaScript is great for understanding basic programing principles along with object oriented syntax. jQuery sticks to its motto of write less, do more.

For more information visit this site .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM