0

使用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

4

1 回答 1

0

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

于 2021-07-08T15:53:26.370 回答