pratik227 / quasar-qgrid

QGrid is a Quasar App Extension. It allows you to filter data for each column, Drag and Drop Rows and also allows you to filter data using header filters.
https://next-quasar-qgrid.netlify.app/
MIT License
112 stars 92 forks source link

cannot filter when passing string from a parent component. #94

Closed iampawan31 closed 1 year ago

iampawan31 commented 1 year ago

I am using a separate input field for adding a filter to my QGrid table. The problem is, I am sending the filter prop to QGrid, but nothing happens. I checked the source code and it doesn't accept filter as a Prop. Can we have a functionality similar to the QTable component where a filter value can be passed as a prop?


  <div class="q-pa-md">
    <q-table
      ref="tableRef"
      title="Treats"
      :rows="rows"
      :columns="columns"
      row-key="id"
      v-model:pagination="pagination"
      :loading="loading"
      :filter="filter"
      binary-state-sort
      @request="onRequest"
    >
      <template v-slot:top-right>
        <q-input borderless dense debounce="300" v-model="filter" placeholder="Search">
          <template v-slot:append>
            <q-icon name="search" />
          </template>
        </q-input>
      </template>

    </q-table>
  </div>
</template>
pratik227 commented 1 year ago

You can use global_search props pass it as true.

iampawan31 commented 1 year ago

But that creates an input field as part of QGrid. I am using a separate input field as part of the parent component.

<template>
  <q-input v-model="filter" />
  <q-grid :data="data" :columns="columns" :filter="filter" :global-search="true"></q-grid>
</template>

<script>
import {defineComponent, ref} from 'vue'

const filter = ref('')

const columns = [
  {
    name: 'name',
    required: true,
    label: 'Dessert (100g serving)',
    align: 'left',
    field: 'name',
    sortable: true
  },
  {name: 'calories', align: 'center', label: 'Calories', field: 'calories', sortable: true},
  {name: 'fat', label: 'Fat (g)', field: 'fat', sortable: true},
  {name: 'carbs', label: 'Carbs (g)', field: 'carbs'},
  {name: 'protein', label: 'Protein (g)', field: 'protein'},
  {name: 'sodium', label: 'Sodium (mg)', field: 'sodium'},
  {
    name: 'calcium',
    label: 'Calcium (%)',
    field: 'calcium',
    sortable: true,
    sort: (a, b) => parseInt(a, 10) - parseInt(b, 10)
  },
  {
    name: 'iron',
    label: 'Iron (%)',
    field: 'iron',
    sortable: true,
    sort: (a, b) => parseInt(a, 10) - parseInt(b, 10)
  }
]

const data = [
  {
    name: 'Frozen Yogurt',
    calories: 159,
    fat: 6.0,
    carbs: 24,
    protein: 4.0,
    sodium: 87,
    calcium: '14%',
    iron: '1%'
  },
]

export default defineComponent({
  name: "Basic",
  setup() {
    return {
      columns,
      data,
      filter
    }
  }
})
</script>

How do i pass the filter prop to QGrid without using the inbuilt search slot?

pratik227 commented 1 year ago

Hi @iampawan31 ,

Just published new version you can just pass your v-model in global_filter and it will work. No need to pass :global-search="true"

Try to install new version it will work.

<q-grid :data="data" :columns="columns" :global_filter="global_filter" ></q-grid>

iampawan31 commented 1 year ago

@pratik227 Hi, I see that you have added changes to a new branch but it still has not merged with the default branch. I am not able to see the changes even when I update the plugin in my quasar app.

pratik227 commented 1 year ago

Make sure it's not taking package from cache. UI version -> 1.0.17

iampawan31 commented 1 year ago
Screenshot 2023-03-13 at 5 41 03 PM

The version you mentioned doesn't show up.

pratik227 commented 1 year ago

It's ui version not app extension version

pratik227 commented 1 year ago

Try to remove node-modules and install all using npm install

pratik227 commented 1 year ago
Screenshot 2023-03-13 at 5 41 03 PM

The version you mentioned doesn't show up.

https://www.npmjs.com/package/quasar-ui-qgrid

iampawan31 commented 1 year ago

@pratik227 Used the Npm version. Its working now. Thank you so much. Happy Coding :)