jQuery implements the row and column of the table to display the corresponding data

jQuery implements the row and column of the table to display the corresponding data

  • Requirements
    Fill the corresponding grid with color according to the interface data
    insert image description here
// 循环数组设置第几行第几列的数据
    function getTableTh() {
    
    
        arrange_list.forEach((item, index) => {
    
     // arrange_list为接口传来的数组
            item.time_list.forEach((element, i) => {
    
    
                $('#cw_drag_table th').each(function() {
    
     // 循环表格th
                    if ($(this).text() == element.title) {
    
    
                        add_data(index + 1, i + 1, element.order_count) // index + 1为第几行,i + 1为第几列,element.order_count为格子要显示的数据
                    }
                })
            });
        });
    }


    // 给表格设置颜色,并按要求显示订单数
    function add_data(row_num, c_num, data) {
    
    
        var tb = $('#cw_drag_table')
        if (tb.length > 0) {
    
    
            var trs = tb.find('tr');
            var tds = $(trs[row_num]).find('td');
            var td = tds[c_num];
            if (data > 0) {
    
    
                // 按天查看,方格标上颜色,不需要显示订单数
                // 按周、按月查看,方格标上颜色,并显示订单数
                if ($('.select_date_active').val() == '1' || $('.select_date_active').val() == '2') {
    
    
                    $(td).addClass('is_green')
                } else {
    
    
                    $(td).html(data);
                    $(td).addClass('is_green')
                }
            }
        }
    }

Guess you like

Origin blog.csdn.net/ARLENE2/article/details/129126762
Recommended