3

W2UI 网格

我想像在 datatables .net 中那样进行网格搜索

它使用'AND'以空格分隔的搜索文本的条件。

我的要求是不要使用搜索框旁边已经存在的高级搜索,因为它是基于特定列的。

"records": [
{ "recid": 1, "fname": "John", "lname": "Doe", "email": "jdoe@gmail.com", "sdate": "4/3/2012" },
{ "recid": 2, "fname": "John", "lname": "Motzart", "email": "jdoe@gmail.com", "sdate": "4/3/2012" },
{ "recid": 3, "fname": "John", "lname": "Franson", "email": "jdoe@gmail.com", "sdate": "4/3/2012" },
{ "recid": 4, "fname": "Susan", "lname": "Franson", "email": "jdoe@gmail.com", "sdate": "4/3/2012" },
{ "recid": 5, "fname": "Kelly", "lname": "Franson", "email": "jdoe@gmail.com", "sdate": "4/3/2012" },
{ "recid": 6, "fname": "Francis", "lname": "Franson", "email": "jdoe@gmail.com", "sdate": "4/3/2012" },
{ "recid": 7, "fname": "Mark", "lname": "Welldo", "email": "jdoe@gmail.com", "sdate": "4/3/2012" },
{ "recid": 8, "fname": "Thomas", "lname": "Bahh", "email": "jdoe@gmail.com", "sdate": "4/3/2012" },
{ "recid": 9, "fname": "Sergei", "lname": "Rachmaninov", "email": "jdoe@gmail.com", "sdate": "4/3/2012" }
]

现在在w2ui网格搜索框中我正在搜索“John”然后它应该显示1,2,3 records

然后我正在搜索“john fran”然后它应该只显示3rd record.

如何做到这一点?

我尝试按空格分割搜索框字符串并在 w2ui.js 中进行了更改,但它总是搜索搜索字符串中的最后一个单词,

请帮忙,谢谢:) :)

4

1 回答 1

0

最简单的方法是在您的记录中添加一个新的“全名”值。

records: [
{ "recid": 1, "fname": "John", "lname": "Doe", "email": "jdoe@gmail.com", "sdate": "4/3/2012", "fullname": "John Doe" },
{ "recid": 2, "fname": "John", "lname": "Motzart", "email": "jdoe@gmail.com", "sdate": "4/3/2012", "fullname": "John Motzart" },
{ "recid": 3, "fname": "John", "lname": "Franson", "email": "jdoe@gmail.com", "sdate": "4/3/2012", "fullname": "John Franson" },
{ "recid": 4, "fname": "Susan", "lname": "Franson", "email": "jdoe@gmail.com", "sdate": "4/3/2012", "fullname": "Susan Franson" },
{ "recid": 5, "fname": "Kelly", "lname": "Franson", "email": "jdoe@gmail.com", "sdate": "4/3/2012", "fullname": "Kelly Franson" },
{ "recid": 6, "fname": "Francis", "lname": "Franson", "email": "jdoe@gmail.com", "sdate": "4/3/2012", "fullname": "Francis Franson" },
{ "recid": 7, "fname": "Mark", "lname": "Welldo", "email": "jdoe@gmail.com", "sdate": "4/3/2012", "fullname": "Mark Welldo" },
{ "recid": 8, "fname": "Thomas", "lname": "Bahh", "email": "jdoe@gmail.com", "sdate": "4/3/2012", "fullname": "Thomas Bahh" },
{ "recid": 9, "fname": "Sergei", "lname": "Rachmaninov", "email": "jdoe@gmail.com", "sdate": "4/3/2012", "fullname": "Sergei Rachmaninov" }

然后您可以将此属性添加到您的网格中,以根据“全名”值搜索数据。

searches: [
            { field: 'fullname', caption: 'Name', operator: 'begins', type: 'text' }
        ]
于 2019-07-30T08:40:38.560 回答