2013-07-26 31 views
0

我有一个作为Jquery数据表运行的表。我有以下要求Jquery Datatables OnSort更新列与来自另一列的图

当一列用户各种各样然后

  1. 我需要indentify列
  2. 根据这个排序列,我想从另一列是不可见的价值用户
  3. 使用此值我想更新表中的第一列。这是一个可见列

我已绑定某种事件与一个叫eventFired按照例子功能表上 http://datatables.net/release-datatables/examples/advanced_init/dt_events.html

最好的,我能得到自己低于

function eventFired(type) {  
      var oTable = $('#tabOverlayLeagueTable').dataTable(); //select table 
      var oSettings = oTable.fnSettings(); //get settings 
      var sortByindex = oSettings.aaSorting[0][0];//get index of sort column 
      //var nNodes = oTable.fnGetNodes(); // I am not sure if I should use this 
      var data = oTable.fnGetData(); // I get the data from this call 

      // loop then data rows 
      for (var i = 0; i < data.length; i++) { 

       // update the first column in the table 
       // with a specific column (this is a hidden column). In 
       //example its cashiers rank figure 
       oTable.fnUpdate(data[i].CashierRank, i, 0); 
      }    
} 

问题

  1. 这可能不是解决我的问题的最佳方法
  2. 我想通过索引而不是名称得到列data[i].CashierRank
  3. 该代码不起作用。似乎永远循环!

回答

0

我希望这有助于

问题1: 凭直觉,我会说这是更好,当你完成所有的数据修改,只需一次更新整个表。

问题2: 您可以通过索引访问到列描述获得属性的名称:

var colName = oSettings.aoColumns[sortByindex].mData 

问题3: 这是奇怪的。这是一个简单的,所以... 当你说它永远循环你的意思是指数趋于无限,而不是停在长度?我认为,也许你每次执行这个表都要执行这个函数,o当你更新这些列时,表认为它正在被排序。在这种情况下,你正在创建一个无限循环,因为你在for内部调用了渲染(使用fnUpdate),并且在更改所有值之后更新整个表,正如我在1.中所说的,它应该被解决。