Hej, mam jakiś problem z filtrowaniem tabelki. Wpisy zostają poprawnie wyświetlone w tabeli, wpisując frazę w search tabelka reaktywnie się zawęża. Ale gdy kasuję search nie wraca do pierwotnej postaci. Co robię nie tak?
<template>
<div class="page">
<div class="card">
<input type="text" v-model="search" @input="searchItems()" />
</div>
<div class="card-body">
<Datatable :table-header="tableHeader" :table-data="tableData" />
</div>
</div>
</template>
i część js
export default defineComponent({
name: "transactions-listing",
components: {
Datatable,
},
setup() {
const tableHeader = ref([
{
name: "Nazwa",
key: "name",
},
// ...
]);
const tableData = ref<Array<ITransaction>>([]);
const search = ref<string>("");
onMounted(() => {
getTransactions();
});
const getTransactions = (): void => {
ApiService.postRequest("api/dev/transactions", params)
.then(({ data }) => {
tableData.value.splice(0, tableData.value.length, ...data);
})
.catch(({ response }) => {
console.log("API Request went wrong.");
});
};
const filterRows = () => {
if (search.value !== "") {
let temp: Array<ITransaction> = [];
temp = tableData.value.filter((item) =>
item.acronym.includes(search.value)
);
tableData.value.splice(0, tableData.value.length, ...temp);
}
return {
tableHeader, tableData, search, filterRows,
};
},
});