简体   繁体   中英

How to grab a row from a html table if a cell equals my query?

Hello everyone I have a datatable where I need to grab the rows that have a value in the colum[x] if it equals my "Variable"

The scenario is a asp.net webapp using mvc5.

To initialize my html I get the values I need on it from a DataTable

foreach (System.Data.DataRow dr in dt_MyDataTable.Rows)
{
   string cust_id = dr["cust-id"].ToString();
   string name = dr["name"].ToString();
   string type = dr["type"].ToString();
   string number = dr["number"].ToString();
   string data = dr["data"].ToString();
   int qa = dr["qa"];
   int tty = dr["tty"];
}

How can I get all the rows that match "myValue" in the column[name] so I can get all the "qa" & "tty" values to make a total sum out of them and use them in this highchart as a category.

For example in my table I have the names "Turtles", "Tacos", "Lemons", "Peppers", "Worms".

How can I retrieve all Turtles "tty" and "qa" values, make a sum of their total and add Turtles as a category in the highcarts using "tty" as aa column total in the highchart??

Can this be done using javascript only or do I have to use c#?

 <script src="https://code.highcharts.com/highcharts.js"></script> <figure class="highcharts-figure"> <div id="container"></div> <p class="highcharts-description"> </p> </figure> <script> Highcharts.chart('container', { title: { text: '' }, xAxis: { categories: ['category1', 'category2', 'category3', 'category4', 'category5'] }, labels: { items: [{ html: 'Total data', style: { left: '50px', top: '18px', color: ( // theme Highcharts.defaultOptions.title.style && Highcharts.defaultOptions.title.style.color ) || 'black' } }] }, series: [{ type: 'column', name: 'Total data1', data: [7, 2, 1, 3, 4] }, { type: 'column', name: 'Total data2', data: [2, 3, 5, 7, 6] }, { type: 'column', name: 'Total data3', data: [4, 3, 3, 9, 0] }, { type: 'spline', name: 'Average', data: [3, 2.67, 3, 6.33, 3.33], marker: { lineWidth: 2, lineColor: Highcharts.getOptions().colors[3], fillColor: 'white' } }, { type: 'pie', name: '', data: [{ name: 'Total data1', y: 85, color: Highcharts.getOptions().colors[0] // Jane's color }, { name: 'Total data2', y: 155, color: Highcharts.getOptions().colors[1] // John's color }, { name: 'Total data3', y: 12, color: Highcharts.getOptions().colors[2] // Joe's color }], center: [100, 80], size: 100, showInLegend: false, dataLabels: { enabled: false } }] }); </script> <style> .highcharts-figure, .highcharts-data-table table { min-width: 310px; max-width: 800px; margin: 1em auto; } #container { height: 400px; } .highcharts-data-table table { font-family: Verdana, sans-serif; border-collapse: collapse; border: 1px solid #EBEBEB; margin: 10px auto; text-align: center; width: 100%; max-width: 500px; } .highcharts-data-table caption { padding: 1em 0; font-size: 1.2em; color: #555; } .highcharts-data-table th { font-weight: 600; padding: 0.5em; } .highcharts-data-table td, .highcharts-data-table th, .highcharts-data-table caption { padding: 0.5em; } .highcharts-data-table thead tr, .highcharts-data-table tr:nth-child(even) { background: #f8f8f8; } .highcharts-data-table tr:hover { background: #f1f7ff; } </style>

i amn't used to work with highcarts but clearly you can get the series in the table

 let chart1 = Highcharts.chart('container', {/*chart options*/});
let series = chart1? chart1.userOptions.series:[];

now series have table columns and graphs each object contain the type(ex column,pie) and data array which holds the values of columns.

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