クラスベースの DataTable には、https: //github.com/pivotal-energy-solutions/django-datatable-view で django-datatable-view を使用します。
それはすべて機能し、ロードしていますが、データの検索に問題があります。入力した文全体を検索する方法がわかりません。現時点では、単語ごとに検索しているようです。
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)
「new test」を検索すると 2 回検索されるため、「new」の結果と「test」の結果が得られます。必要なのは、「新しいテスト」の結果だけです。
印刷物は検索されているものを示します
<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