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 authToken: ""
|
||||||
|
property string searchText: "" // Property to hold the search text
|
||||||
|
|
||||||
signal logout()
|
signal logout()
|
||||||
|
|
||||||
|
@ -34,9 +35,14 @@ Rectangle {
|
||||||
anchors.margins: 5
|
anchors.margins: 5
|
||||||
|
|
||||||
TextField {
|
TextField {
|
||||||
|
id: searchField
|
||||||
placeholderText: qsTr("Search")
|
placeholderText: qsTr("Search")
|
||||||
Layout.alignment: Qt.AlignVCenter
|
Layout.alignment: Qt.AlignVCenter
|
||||||
Layout.fillWidth: true
|
Layout.fillWidth: true
|
||||||
|
onTextChanged: {
|
||||||
|
searchText = text
|
||||||
|
filterModel() // Filter model based on search text
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Button {
|
Button {
|
||||||
|
@ -104,7 +110,7 @@ Rectangle {
|
||||||
Layout.fillHeight: true
|
Layout.fillHeight: true
|
||||||
clip: true
|
clip: true
|
||||||
boundsBehavior: Flickable.StopAtBounds
|
boundsBehavior: Flickable.StopAtBounds
|
||||||
model: apiDataModel
|
model: filteredApiDataModel // Use the filtered model
|
||||||
|
|
||||||
delegate: Rectangle {
|
delegate: Rectangle {
|
||||||
width: listView.width
|
width: listView.width
|
||||||
|
@ -129,6 +135,10 @@ Rectangle {
|
||||||
ListModel {
|
ListModel {
|
||||||
id: apiDataModel
|
id: apiDataModel
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ListModel {
|
||||||
|
id: filteredApiDataModel
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -162,6 +172,7 @@ Rectangle {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
filterModel() // Filter the model after loading data
|
||||||
} else {
|
} else {
|
||||||
console.log("Error: " + xhr.status);
|
console.log("Error: " + xhr.status);
|
||||||
}
|
}
|
||||||
|
@ -169,4 +180,19 @@ Rectangle {
|
||||||
}
|
}
|
||||||
xhr.send();
|
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