在DTETIT中使用JS实施单个列搜索
在我的数据表中,我想实现此页面中显示的单个列搜索:
>过滤器参数。因此,我正在尝试使用datatable.options.options
参数dtedit
来实现单个列搜索。
在dtedit
中,我可以将JS代码与以下代码合并:
jsc <- `Some JS code`
dtedit(input,
output,
name = "input_table",
thedata = design,
...,
datatable.options = list(initComplete = JS(jsc))
)
我的JS技能不存在,并且我需要帮助弄清楚如何在我的dtedit
中使用以下JS代码
$(document).ready(function() {
// Setup - add a text input to each footer cell
$('#example tfoot th').each( function () {
var title = $(this).text();
$(this).html( '<input type="text" placeholder="Search '+title+'" />' );
} );
// DataTable
var table = $('#example').DataTable({
initComplete: function () {
// Apply the search
this.api().columns().every( function () {
var that = this;
$( 'input', this.footer() ).on( 'keyup change clear', function () {
if ( that.search() !== this.value ) {
that
.search( this.value )
.draw();
}
} );
} );
}
});
} );
In my datatable, I would like to implement individual column searching shown in this page:
https://datatables.net/examples/api/multi_filter.html
I am using DTedit
R package, an extension to DT
, and it doesn't have the convenient filter
argument. So, I am trying to use the datatable.options
argument inside dtedit
to implement individual column searching.
In dtedit
, I can incorporate JS code with the following code:
jsc <- `Some JS code`
dtedit(input,
output,
name = "input_table",
thedata = design,
...,
datatable.options = list(initComplete = JS(jsc))
)
My JS skills are non existent and I need help on figuring out how to use the following JS code in my dtedit
$(document).ready(function() {
// Setup - add a text input to each footer cell
$('#example tfoot th').each( function () {
var title = $(this).text();
$(this).html( '<input type="text" placeholder="Search '+title+'" />' );
} );
// DataTable
var table = $('#example').DataTable({
initComplete: function () {
// Apply the search
this.api().columns().every( function () {
var that = this;
$( 'input', this.footer() ).on( 'keyup change clear', function () {
if ( that.search() !== this.value ) {
that
.search( this.value )
.draw();
}
} );
} );
}
});
} );
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是我将如何处理
dt
软件包:我不熟悉
dtedit
。但是我看了一下文档,看来它不接受容器
选项。不幸的是,不可能将页脚添加到使用JavaScript的DataTable中。Here is how I would do with the
DT
package:I am not familiar with
DTedit
. But I took a look at the doc and it seems that it doesn't accept thecontainer
option. And unfortunately, it's not possible to add a footer to a datatable with JavaScript.