2

我有一个表格,其中有一个列使用slot-scope,我无法将该列数据放入过滤器选项。

代码

Component filter input

<el-input v-model="filters[0].value" placeholder="Type to filter"></el-input>

component HTML

问题部分已评论

<data-tables class="bg-white shadow-sm"
    :data="transits"
    :filters="filters"
    style="width: 100%">
    <el-table-column prop="name" label="Name" sortable="custom"></el-table-column>
    <el-table-column label="Barcode" sortable="custom"> <!-- can't get this data into filter -->
        <template slot-scope="scope">
            <div v-if="scope.row.barcode.serial_number">
                {{scope.row.barcode.serial_number}}
            </div>
            <template v-else>
                {{scope.row.barcode.u_serial_number}}
            </template>
        </template>
    </el-table-column>
</data-tables>

Component Script

我在过滤器函数中提供了更多列示例,以便您了解element-ui表格背后的逻辑

<script>
export default {
    props: ['user'],
    name: "adminOuterTransits",
    data() {
        return {
            transits: [],
            filters: [
                {
                    value: '',
                    prop: ['formNo', // works (belongs to transit table)
                            'receiptNo', // works (belongs to transit table)
                            'description', // works (belongs to transit table)
                            'fob', // works (belongs to transit table)
                            'gudang', // works (belongs to transit table)
                            'ship_via', // works (belongs to transit table)
                            'sent_at', // works (belongs to transit table)
                            'received_at', // works (belongs to transit table)
                            'barcode'], // DOESN'T WORK (IT'S RELATIONSHIP DATA "barcode.serial_number")
                }
            ]
        }
    },
    // rest of it....
}
</script>

知道如何将条形码数据包含到过滤器输入中吗?

4

1 回答 1

0

也许下次在 element-ui 上提及扩展更好https://www.njleonzhang.com/vue-data-tables/#/en-us/ ;)

但是要解决您的问题,您要过滤的道具barcode必须自己编写filterFn,因为没有定义el-table-column道具所以道具是undefined https://www.njleonzhang.com/vue-data-tables/#/en -us/filter?id=leverage-filterfn

另请查看https://www.njleonzhang.com/vue-data-tables/#/en-us/filter?id=principle-of-data-tables39-filter提供的图表


如果您不想使用vue-data-tables,您也可以computed像 element-ui 页面上的示例中那样使用数据集:https ://element.eleme.io/#/en-US/component/table#table-with -自定义标题

于 2020-08-21T08:19:01.397 回答