native: add search support
This commit is contained in:
parent
8a6ba829c0
commit
4306f561a6
1 changed files with 27 additions and 1 deletions
|
@ -15,6 +15,7 @@ Rectangle {
|
|||
}
|
||||
|
||||
property string authToken: ""
|
||||
property string searchText: "" // Property to hold the search text
|
||||
|
||||
signal logout()
|
||||
|
||||
|
@ -34,9 +35,14 @@ Rectangle {
|
|||
anchors.margins: 5
|
||||
|
||||
TextField {
|
||||
id: searchField
|
||||
placeholderText: qsTr("Search")
|
||||
Layout.alignment: Qt.AlignVCenter
|
||||
Layout.fillWidth: true
|
||||
onTextChanged: {
|
||||
searchText = text
|
||||
filterModel() // Filter model based on search text
|
||||
}
|
||||
}
|
||||
|
||||
Button {
|
||||
|
@ -104,7 +110,7 @@ Rectangle {
|
|||
Layout.fillHeight: true
|
||||
clip: true
|
||||
boundsBehavior: Flickable.StopAtBounds
|
||||
model: apiDataModel
|
||||
model: filteredApiDataModel // Use the filtered model
|
||||
|
||||
delegate: Rectangle {
|
||||
width: listView.width
|
||||
|
@ -129,6 +135,10 @@ Rectangle {
|
|||
ListModel {
|
||||
id: apiDataModel
|
||||
}
|
||||
|
||||
ListModel {
|
||||
id: filteredApiDataModel
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -162,6 +172,7 @@ Rectangle {
|
|||
});
|
||||
}
|
||||
}
|
||||
filterModel() // Filter the model after loading data
|
||||
} else {
|
||||
console.log("Error: " + xhr.status);
|
||||
}
|
||||
|
@ -169,4 +180,19 @@ Rectangle {
|
|||
}
|
||||
xhr.send();
|
||||
}
|
||||
|
||||
function filterModel() {
|
||||
filteredApiDataModel.clear()
|
||||
for (var i = 0; i < apiDataModel.count; ++i) {
|
||||
var item = apiDataModel.get(i)
|
||||
if (item.name.toLowerCase().indexOf(searchText.toLowerCase()) !== -1 ||
|
||||
item.key.toLowerCase().indexOf(searchText.toLowerCase()) !== -1 ||
|
||||
item.amount.toLowerCase().indexOf(searchText.toLowerCase()) !== -1 ||
|
||||
item.start.toLowerCase().indexOf(searchText.toLowerCase()) !== -1 ||
|
||||
item.end.toLowerCase().indexOf(searchText.toLowerCase()) !== -1 ||
|
||||
item.group.toLowerCase().indexOf(searchText.toLowerCase()) !== -1) {
|
||||
filteredApiDataModel.append(item)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue