簡體   English   中英

我需要比較html表行中的數據

[英]I need to compare the data in rows of a html table

我正在使用javascript循環創建由數字組成的表格。 該代碼當前可以很好地創建表格,並且我為其添加了一些樣式。 我遇到的問題是找到一種方法來比較單元格列中的數據,以便突出顯示該列中該組中性能最佳和最差的數據。

這是我正在使用的javascript函數。

function performanceMetricsLoad() {
var records = storePerformanceMetricsData.getRecordsValues();
var groupTracker = null;
var assetTracker = null;
var htmlStr;
htmlStr = "<table class='TableStyles'><thead class='HeaderStyles'><tr><th width='400'>Name</th><th width='110'>1 month Cumulative Performance to "
            + records[0].DatetimeRecorded.format("F j, Y") + "</th><th width='110'>3 month Cumulative Performance to "
            + records[0].DatetimeRecorded.format("F j, Y") + "</th><th width='110'>6 month Cumulative Performance to "
            + records[0].DatetimeRecorded.format("F j, Y") + "</th><th width='110'>12 month Cumulative Performance to " 
            + records[0].DatetimeRecorded.format("F j, Y") + "</th></tr></thead><tbody>";

for (var i = 0; i < records.length; i++) {

    if (groupTracker != records[i].ClassOption) {
        htmlStr += "<tr>" + "<td class='GroupStyleCSS' colspan='5'>" 
        + records[i].Diversification + "</td></tr>";
        groupTracker = records[i].ClassOption;
    }

    if (groupTracker == records[i].ClassOption) {
        htmlStr += "<tr>" + "<td class='RecordCssStyle'>" + records[i].AssetLongName
        + "</td>"+ "<td class='RecDiv'>" + records[i].TotalReturn1m.toFixed(2)
        + "</td>" + "<td class='RecDiv'>" + records[i].TotalReturn3m.toFixed(2)
        + "</td>" + "<td class='RecDiv'>" + records[i].TotalReturn6m.toFixed(2) 
        + "</td>" + "<td class='RecDiv'>" + records[i].TotalReturn12m.toFixed(2) + "</tr>"; 
        assetTracker = records[i].AssetLongName;
    }
}

htmlStr += "</tbody></table>";
createRow("", htmlStr);
frmMetrics.doLayout();

}

function createRow(cls, text) {
frmMetrics.add(new Ext.BoxComponent({
    cls: cls,
    html: "<div>" + text + "</div>"
}));

}

信息被輸出到EXT formPanel中。

我現在遇到的問題是我要輸出所需的信息,以找到一種方法來突出顯示各列中各組中的最佳和最差表現。

該表沿頂部輸出5欄,在基金名稱的左下方最多顯示10組,這些名稱根據其“多樣化”進行分組,具體取決於使用SQL查詢請求的信息。

有人知道我可以用這段代碼的當前狀態執行此操作嗎? 我正在考慮使用另一個外部函數,可能還會使用某些if語句選擇不同的CSS類...任何幫助將不勝感激。 非常感謝。

抱歉,缺少屏幕截圖,我嘗試添加一些截圖,但顯然我需要信譽評分為10,然后才能沿此路線前進...

將這兩行添加到函數頂部

var largest;
var smallest;

然后在循環中添加:

if(value > largest){
    largest = value;
}
if(value < smallest){
    smallest = value;
}

如果要使用這些值向單元格添加樣式,請添加一行以存儲這些值的索引(以相同的方式更新),然后設置或並使用CSS選擇ID。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM