Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CDataTable not showing columnFilter on external datasource #113

Closed
ayrtonandino opened this issue Jul 24, 2020 · 2 comments
Closed

CDataTable not showing columnFilter on external datasource #113

ayrtonandino opened this issue Jul 24, 2020 · 2 comments
Labels
bug

Comments

@ayrtonandino
Copy link

@ayrtonandino ayrtonandino commented Jul 24, 2020

I have a datatable that lazyload from an api.

I’m using "@coreui/vue": "^3.1.1"

<CDataTable
    :sorter="{ external: true }"
    :columnFilter="{ external: true, lazy: true }"
    :tableFilter="{ external: true, lazy: true }"
    @pagination-change="changeItemsLimit"
    :sorter-value.sync="passedSorter"
    :column-filter-value.sync="columnFilter"
    :table-filter-value.sync="tableFilter"
    :loading="loading"
    :items-per-page-select="true"
    :items="items"
    :fields="fields"
>
...
</CDataTable>

When the api return empty items: [], result from a column being filtered and no matching data, the entire “columns filters” row disappear.

This is a problem when you have a lot of columns being filtered and only one that doesn’t match anything, you must remove all filters and start from scratch.

Looking at the component, the problem is that it checks if the column is present in the items array, which is empty.

<!-- line 96 from CDataTable.vue -->
<tr v-if="columnFilter" class="table-sm">
    <template v-for="(colName, index) in rawColumnNames" >
        <th :class="headerClass(index)" :key="index">
            <slot :name="`${rawColumnNames[index]}-filter`">
                <input
                v-if="itemsDataColumns.includes(colName) && 
                        (!fields || fields[index].filter !== false)"
                class="form-control form-control-sm"
                @input="columnFilterEvent(colName, $event.target.value, 'input')"
                @change="columnFilterEvent(colName, $event.target.value, 'change')"
                :value="columnFilterState[colName]"
                :aria-label="`column name: '${colName}' filter input`"
                />
            </slot>
        </th>
    </template>
</tr>

I would suggest changing this

v-if="itemsDataColumns.includes(colName) && 
     (!fields || fields[index].filter !== false)"

To something like this?

// untested, works for my use case
v-if="
    (itemsDataColumns.includes(colName) || columnFilter.external)
     &&
    (!fields || fields[index].filter !== false)
"
@woothu woothu added the bug label Jul 24, 2020
@woothu
Copy link
Contributor

@woothu woothu commented Jul 24, 2020

The problem with your solution is that column with no data would have a column filter when there are no items, and no filter when the items are there.

So the solution is to remove automatic column filter removal when column doesn't have data, this feature was introduced in 3.1.0 version:
8976054#diff-0f3bc2a0701817028951551a8e56d6f2R101

woothu added a commit that referenced this issue Jul 24, 2020
@woothu
Copy link
Contributor

@woothu woothu commented Jul 24, 2020

Fixed in 3.1.2 version release.

@woothu woothu closed this Jul 24, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.