如何禁用特定DataTable列中的搜索? [英] How to disable searching in specific DataTable columns?

查看:88
本文介绍了如何禁用特定DataTable列中的搜索?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在成功使用此代码

function refreshDataTable() {
        // The table is made sortable
        $('#order_proposal_table').DataTable({
            'destroy'           : true,     // see http://datatables.net/manual/tech-notes/3#destroy - 2nd example
            'paging'            : false,
            'scrollCollapse'    : true,
            'scrollY'           : '65vh',
            'fixedHeader'       : true,
            'dom'               : 'rt',
        }); 
    }

然后,我尝试在9列中的2列中启用搜索.

Then I'm trying to enable searching in 2 of the 9 columns.

所以我改变了

'dom'               : 'rt',

进入

'dom'               : 'frt',

显示查找输入框.该方法有效,但它会搜索每列,但我只需要搜索两列.

To show the find input box. This works, but it searches trough every columns, but I need to search only into 2 columns.

因此,我正在尝试遵循此官方指南,有选择地禁用过滤功能,并且添加columns定义

So I'm trying to follow this official guide to disable filtering selectively, and add columns definition

结果代码:

function refreshDataTable() {
        // The table is made sortable
        $('#order_proposal_table').DataTable({
            'destroy'           : true,     // see http://datatables.net/manual/tech-notes/3#destroy - 2nd example
            'paging'            : false,
            'scrollCollapse'    : true,
            'scrollY'           : '65vh',
            'fixedHeader'       : true,
            'dom'               : 'frt',
            'columns'           : [         // see https://datatables.net/reference/option/columns.searchable
                { 'searchable': false },
                { 'searchable': false },
                null,   // product code 
                null,   // description 
                { 'searchable': false }
            ]
        }); 
    }

问题是我在数据表javascript中遇到了javscript错误

The problem is that I've a javscript error from the datatable javascript

TypeError:col未定义

TypeError: col is undefined

删除columns代码即可.

我在做什么错了?

推荐答案

我使用columnsDef选项解决了.

以下代码禁用了对指定列的搜索.正是我想要的.

The following code disabled search for the specified columns. Exactly what I wanted.

'columnDefs'        : [         // see https://datatables.net/reference/option/columns.searchable
                { 
                    'searchable'    : false, 
                    'targets'       : [0,1,4,5,6,7,8,9] 
                },
            ]

这篇关于如何禁用特定DataTable列中的搜索?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆