简体   繁体   English

在数据表中编辑后突出显示行

[英]highlight row after edit in datatables

I new to Jquery and Javascript. 我是Jquery和Javascript的新手。

I am using datatables to show some data 我正在使用数据表来显示一些数据

I am trying to highlight specific rows, ie : rows that have been edited after inline edit. 我试图突出显示特定的行,即:在内联编辑后编辑的行。 I am using the inline edit (from https://github.com/ejbeaty/CellEdit ). 我正在使用内联编辑(来自https://github.com/ejbeaty/CellEdit )。 The code that I have modified in " Advanced.js" is as follows : 我在“Advanced.js”中修改过的代码如下:

    function myCallbackFunction (updatedCell, updatedRow, oldValue) {



   if (updatedCell.data() == "Bradley")
        {
            console.log("highlight required for Name Bradley")
            $(updatedRow).css( "background-color", "Orange" )

        }

    console.log("The new value for the cell is: " + updatedCell.data());
    console.log("The old value for that cell was: " + oldValue);
    console.log("The values for each cell in that row are: " + updatedRow.data());
}

In the callback function I am trying to change the background color for a specific name. 在回调函数中,我试图更改特定名称的背景颜色。 I can see the console.log but the color changes seem to have not taken up. 我可以看到console.log但颜色变化似乎没有占用。

Did not knew this CellEdit plugin before, but it looks to be really nice, decent and straight forward. 以前不知道这个CellEdit插件,但它看起来非常好,体面和直接。 Instead of copying an example it is sometimes better to produce a small minimal example from scratch. 不是复制示例,有时最好从头开始生成一个小的最小示例。 Look at this 看这个

var table = $('#example').DataTable({
}).MakeCellsEditable({
  onUpdate: function(cell, row, oldValue) { 
    if (cell.data() != oldValue) {
      row.nodes().to$().addClass('highlight')
    }   
  }
})  

I forgot .nodes() in the comment, sorry for that - but the above works -> http://jsfiddle.net/Lccju5bq/ 我在评论中忘记了.nodes() ,对不起 - 但上面的工作 - > http://jsfiddle.net/Lccju5bq/

try this ` 试试这个`

  if (updatedCell.data() == "Bradley")
    {
        console.log("highlight required for Name Bradley")
        var updatedRow = document.getElementbyId("updatedRow);
        updatedRow.style.background = 'black';

    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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