Javascript 更改数据表搜索标签

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/29929022/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-23 04:20:26  来源:igfitidea点击:

Change DataTable Search Label

javascriptjquerydatatables

提问by efecarranza

Been trying to change the Search: to Filter: in my datatable that I created.

一直在尝试将 Search: 更改为 Filter: 在我创建的数据表中。

I tried this that i found:

我试过这个,我发现:

$(document).ready(function() {
oTable = $('#datatable-example_filter').dataTable({
  "aaSorting": [[ 10, "desc" ]],
  "bJQueryUI": true,
  "aLengthMenu": [[25, 50, 100, 250, 500, -1], [25, 50, 100, 250, 500, "All"]],
  "sPaginationType": "full_numbers",
  "oLanguage": {
    "sSearch": "Filter: "
  }
});
} ); 

but it is not working, #datatable-example_filter is the name of the id, inside the div that is generated by dataTable

但它不起作用,#datatable-example_filter 是 id 的名称,在 dataTable 生成的 div 内

回答by devlin carnate

The other answer that uses "oLanguage" is using legacy DataTables api. According to DataTables v 1.10+ documentation, the syntax is:

使用“oLanguage”的另一个答案是使用旧版 DataTables api。根据 DataTables v 1.10+文档,语法是:

$('#example').dataTable( {
  "language": {
    "search": "Filter records:"
  }
} );

回答by Marcelo Rocha

very easy, just put this parameter when you call data table function:

很简单,调用数据表函数的时候加上这个参数即可:

"oLanguage": {
  "sSearch": "<span>YOUR SEARCH TITLE HERE:</span> _INPUT_" //search
}

回答by Paul Gorbas

I have found this code will change the Search Label ( in my case to "Filter results:" before the DataTable get populated with data.

我发现此代码将在 DataTable 填充数据之前更改搜索标签(在我的情况下为“过滤结果:”。

var dataTable_leSrch = $('#dataTable_leSrch').dataTable({
    "oLanguage": {
        "sSearch": "Filter results:"
    }
});

but when I later populate the DataTable with data the label reverted back to "Search:", so I had to add this code to my DataTable configuration to keep the label changed:

但是当我稍后用数据填充 DataTable 时,标签恢复为“搜索:”,因此我必须将此代码添加到我的 DataTable 配置中以保持标签更改:

function fillDataTable(res) {
if ($('#dataTable_leSrch').length !== 0) {
    $('#dataTable_leSrch').DataTable({
        fixedHeader: {
            header: true,
            headerOffset: $('#header').height()
        },
        oLanguage: {
            "sSearch": "Filter results:"
        },
        responsive: false,
        scrollX: true,
        scrollY: 400,
        scrollCollapse: true,
        select: true,
        destroy: true,
        aaData: res.data.Results,
        ...

回答by Andres Paul

Inside the Datatable Javascript (table = $dataTable.DataTable)add the following code:

在 Datatable Javascript 中(table = $dataTable.DataTable)添加以下代码:

language: {
  'search' : '' /*Empty to remove the label*/
}

I left the search empty because I wanted the info to be in the Placeholder

我将搜索留空,因为我希望信息位于占位符中

Ps: If you want to add the placeholder put the following code outside the Datatable initialization

Ps:如果要添加占位符,请将以下代码放在Datatable初始化之外

$('.dataTables_filter input').attr("placeholder", "Zoeken...");

回答by mamal

try this for change labelsearch panel

试试这个更改标签搜索面板

$('#table_id').DataTable({
 "oLanguage": {
                "sSearch": "type somthing.. ",
            },

});

回答by Mourad MAMASSI

// Input text box will be appended at the end automatically
$(document).ready( function() {
  $('#example').dataTable( {
    "oLanguage": {
      "sSearch": "Filter records:"
    }
  } );
} );


// Specify where the filter should appear
$(document).ready( function() {
  $('#example').dataTable( {
    "oLanguage": {
      "sSearch": "Apply filter _INPUT_ to table"
    }
  } );
} );

for more detail check this link http://legacy.datatables.net/usage/i18n

有关更多详细信息,请查看此链接 http://legacy.datatables.net/usage/i18n