2014-03-03 47 views
1

嗨我是新的数据表和JavaScript的一般,我想知道是否有无论如何增加“数据”选项行和数据表中的项目。添加“数据”选项到数据表中的项目

我试图让一个介绍旅游使用http://usablica.github.io/intro.js/

,为了做到这一点,我需要补充数据信息=“”和数据步=“”选项的项目我的网站。

因此,例如,当您使用intro.js您添加具有“数据介绍”和“数据级”选项,如项目:

<h1 data-intro='This is step one.' data-step='1'>The Changelog</h1> 

因为数据表是所有的JavaScript渲染没有方式将其添加到下面的图片中的“显示/隐藏列”按钮和单独的行。这有可能解决吗?

谢谢

enter image description here

enter image description here

这里是显示记录按钮

+0

什么是 “H1” 必须用数据表网格上市? – user2864740

+0

这只是一个示例,表明您需要数据前奏和数据步骤选项 – James

+0

但是*其中*是“h1”,*它如何与DataTable网格相关? “变更日志”与网格中显示的任何*数据有什么关系? – user2864740

回答

3

您可以使用数据表的fnRowCallback选项添加自定义属性表中的行后,他们都创建(see the docs)。

$('#mytable').dataTable({ 
    // Set data for the table here 
    // ... 

    // Add data attributes for intro.js 
    'fnRowCallback': function(nRow, aData, iDisplayIndex, iDisplayIndexFull) { 
     if (aData[1] === 'Firefox 2') { 
      $('td:eq(1)', nRow) 
       .attr('data-intro', 'This column shows the browser type.') 
       .attr('data-step', '1'); 
     } 
    }, 

    // Add data attributes for sections, that do not belong to the table itself 
    'fnInitComplete': function(oSettings, json) { 
     // The number of elements selector seems to have the id of the table + '_length' 
     $('#example_length') 
      .attr('data-intro', 'Select the number of entries to show.') 
      .attr('data-step', '1'); 
    } 
}); 

http://jsfiddle.net/2f2L6/1/

+1

非常感谢你!这太棒了!!你会碰巧知道如何将它们添加到“显示”“实体”按钮?我知道这必须与fnHeaderCallback相关,但我对jquery相当陌生,并且不太了解如何找到“显示实体”标签,其中包含一个名为“显示实体”的标签。 ').dataTable({“n”)[0] .innerHTML =“显示”+(iEnd-iStart)+“记录“; } }); }) – James

+0

”鞋实体“按钮到底是什么,你想用它做什么?如果你想用它启动'intro.js',请参阅链接JSFiddle中的“Start Intro”按钮。这只是一个点击事件。如果您引用表的另一部分,请查看[数据表的完整引用](https://datatables.net/ref)。几乎任何元素都可以在创建后自定义。 – Jan

+0

显示10个条目按钮是在我最近的编辑中发布的表格顶部的按钮。谢谢! – James