【问题标题】:Django Datatables View filter/searchDjango 数据表视图过滤器/搜索
【发布时间】:2021-09-18 20:30:39
【问题描述】:

使用https://github.com/pivotal-energy-solutions/django-datatable-view 的 django-datatable-view 获取基于类的 DataTable。

一切正常并正在加载,但我在搜索数据时遇到了问题。我不知道如何搜索输入的整个句子,目前似乎是按单词搜索。

class StoresDatatable(Datatable):

    class CustomColumn(columns.DisplayColumn):
            def __init__(self, *args, **kwargs):
                self.field = kwargs.get('field', None)
                if self.field: kwargs.pop('field')
                super().__init__(*args, **kwargs)

            def search(self, model, term):
                return Q(**{ '%s__name' % self.field : term })


    attr = CustomColumn(
        'Attrs', 
        'count_attr', # data source 
        field='attributes',
        processor="get_attributes", 
        allow_regex=True
    )

选择过滤器时触发的代码(表外)。

const searchValue = 'new test'
                                           
$(".datatable")
    .DataTable()
    .column(columnIndex)
    .search(searchValue, true, true, false)

搜索“新测试”搜索两次,所以我会得到“新”的结果和“测试”的结果。我需要的只是“新测试”的结果。

打印显示正在搜索的内容

<th data-name="attrs" data-config-sortable="true" data-config-visible="true">Attrs</th>
test
<th data-name="attrs" data-config-sortable="true" data-config-visible="true">Attrs</th>
new

【问题讨论】:

    标签: jquery django django-datatable


    【解决方案1】:

    我错过了文档中提供的一个简单内容。需要用引号括起来,它可以工作!!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-07-28
      • 2012-11-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多