implemented simpleSearch for Employees/Index.
This commit is contained in:
@@ -2,17 +2,15 @@ import { defineStore } from 'pinia'
|
||||
import { useUser } from '@/stores/user'
|
||||
import axios from '@/axios'
|
||||
|
||||
import emplJSON from '../sample-data/employees.json'
|
||||
|
||||
const user = useUser()
|
||||
|
||||
export const useEmployees = defineStore('employees', {
|
||||
state: () => {
|
||||
return {
|
||||
/**
|
||||
* @type {}[]
|
||||
* @type any[]
|
||||
*/
|
||||
rows: Array<Object>(),
|
||||
rows: Array<any>(),
|
||||
|
||||
meta: {
|
||||
current_page: NaN,
|
||||
@@ -22,7 +20,12 @@ export const useEmployees = defineStore('employees', {
|
||||
total: NaN
|
||||
},
|
||||
|
||||
columns: Array<string>()
|
||||
columns: Array<string>(),
|
||||
|
||||
limit: 10,
|
||||
page: 1,
|
||||
sort_by: '',
|
||||
simple_search: ''
|
||||
}
|
||||
},
|
||||
|
||||
@@ -33,28 +36,29 @@ export const useEmployees = defineStore('employees', {
|
||||
* @param: {string} sortBy - QueryString: sort_by=asc(col1),desc(col2),...
|
||||
* @param: {string} simpleSearch - QueryString: simple_search=query(col1,col2,...)
|
||||
**/
|
||||
async fetchFromApi(limit?: number, page?:number, sort_by?: string, simple_search?: string) {
|
||||
async fetchFromApi() {
|
||||
try {
|
||||
const data : any= (await axios.get(
|
||||
|
||||
const data : any = (await axios.get(
|
||||
'/employees',
|
||||
{
|
||||
params: {
|
||||
limit,
|
||||
page,
|
||||
sort_by,
|
||||
simple_search
|
||||
limit: this.limit,
|
||||
page: this.page,
|
||||
sort_by: this.sort_by,
|
||||
simple_search: this.simple_search
|
||||
},
|
||||
headers: user.header
|
||||
}
|
||||
)).data
|
||||
|
||||
Object.assign(this.meta, data?.meta)
|
||||
Object.assign(this.rows, data?.data)
|
||||
Object.assign(this.meta, data.meta)
|
||||
this.rows = data.data.map(e => e)
|
||||
|
||||
this.columns = this.fetchColumns()
|
||||
}
|
||||
catch(err) {
|
||||
|
||||
console.log(err)
|
||||
}
|
||||
},
|
||||
|
||||
@@ -63,6 +67,10 @@ export const useEmployees = defineStore('employees', {
|
||||
return Object.keys(this.rows[0])
|
||||
}
|
||||
return []
|
||||
},
|
||||
|
||||
watch(){
|
||||
|
||||
}
|
||||
}
|
||||
})
|
||||
Reference in New Issue
Block a user