Home > Blockchain >  quasar server side pagination, filter are not working
quasar server side pagination, filter are not working

Time:07-30

I am trying to make a server side pagination, filter system in a quasar app. I am using laravel api for backend source. Problem is, It does not passing parameters (filter, pagination etc) to the server.

My code from vue:

function onRequest (props) {
  const { page, rowsPerPage, sortBy, descending } = props.pagination
  const filter = props.filter
  console.log(rowsPerPage)

  loading.value = true

  // emulate server
  setTimeout(() => {
    const fetchCount = rowsPerPage === 0 ? pagination.value.rowsNumber : rowsPerPage

    // fetch data from "server"
    axios.get('https://api.bdshsystem.com/public/api/v1/branch-list',
    {query: {
      page: page,
      limit: fetchCount,
      keyword: filter,
    }}).then(response => {
      // clear out existing data and add new
      rows.value.splice(0, rows.value.length, ...response.data.data)

      // don't forget to update local pagination object
      pagination.value.page = response.data.meta.current_page
      pagination.value.rowsPerPage = response.data.meta.per_page
      pagination.value.rowsNumber = response.data.meta.total
    })
    loading.value = false
  }, 1500)
}

codes from controller :

public function index(Request $request)
{
    $searchParams   = $request->all();
    $wardQuery    = Ward::query();
    $limit          = Arr::get($searchParams, 'limit', static::ITEM_PER_PAGE);
    $keyword        = Arr::get($searchParams, 'keyword', '');
    try{
        if (!empty($keyword)) {
            $wardQuery->where('name', 'LIKE', '%' . $keyword . '%');
            $wardQuery->orWhere('short_code', 'LIKE', '%' . $keyword . '%');
        }
        return WardResource::collection($wardQuery->paginate($limit));
   }catch (\Exception $ex) {
        $response = [
            'status' => 'Failed',
            'msg' =>  (env('APP_ENV') != 'production')?$ex->getMessage():'Server error' . ' , 
             Please try again.',
            'errdetailed' => (env('APP_ENV') != 'production')? $ex:'',
            'code' => 400
        ];
        return response()->json($response);
   }
}

CodePudding user response:

$request->all() won't give you the query string. Use $request->query() instead:

$wardQuery      = Ward::query();
$limit          = $request->query('limit', static::ITEM_PER_PAGE);
$keyword        = $request->query('keyword', '');
  • Related