【问题标题】:Coloring rows based on row values in Dynatable根据 Dynatable 中的行值对行着色
【发布时间】:2015-11-26 18:36:18
【问题描述】:

我正在尝试根据可以是红色/绿色的“状态”为行着色。 使用 dynatable 根据 JSON 数据生成表行。

问题是每当我从 dynatable 调用以下代码时,它总是被 dyntable.process(); 覆盖。

$('#mytable tr td').each(function() {
    if ($(this).text() == 'Red') {
        $(this).closest('tr').css('background-color', '#f00');
    }
});

我的 index.php: http://pastie.org/10389654

我的 index.js: http://pastie.org/10389656

【问题讨论】:

    标签: javascript php html html-table dynatable


    【解决方案1】:

    查看文档的这一点:Documentation - Event

    并且可能使用dynatable:beforeUpdate 事件

    这样的一些方法:

       var dynatable = $('#mytable').dynatable({
      dataset: {
          ajax: true,
          ajaxUrl: './api.php',
          ajaxOnLoad: true,
          records: []
      },
      params: {
          records: 'data'
      },
      features: {
          paginate: false,
          sort: false,
          pushState: false,
          search: false,
          recordCount: false,
          perPageSelect: false
      }
    }).data('dynatable').bind('dynatable:afterProcess', changeColor);
    

    然后是你的函数

    function changeColor() {
        $('#mytable tr td').each(function() {
            if ($(this).text() == 'Red') {
                $(this).closest('tr').css('background-color', '#f00');
            }
        });
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-12-30
      • 1970-01-01
      • 2016-11-04
      • 1970-01-01
      相关资源
      最近更新 更多