Open stevendesu opened 7 years ago
@stevendesu Maybe you can try using __slot
(scoped slot).
The following code might give you an idea, but I haven't tested it so I'm not sure.
<template>
<vuetable ref="vuetable"
:fields="fields" api-url="..."
>
<template v-for="dep in allPossibleDepartments" :slot="dep" scope="props">
{{ props.departments.indexOf(dep) > 0 ? 'true' : 'false' }}
</template>
</vuetable>
</template>
<script>
var fieldsDef = []
fieldsDef.push({
name: 'order',
title: 'Order #'
})
fieldsDef.push(
allPossibleDepartments.map(dep => {
return {
name: '__slot:' + dep,
title: dep
}
})
)
export default {
data () {
return {
fields: fieldsDef
}
}
}
</script>
@ratiw When I'm home tonight I'll try this out and see if it works.
@ratiw It took a lot of experimentation (stripping away pieces bit by bit to get a minimum test case then making several variations on that test case) but I figured it out
Replace:
<template v-for="dep in allPossibleDepartments" :slot="dep" scope="props">
With:
<div v-for="dep in allPossibleDepartments" :slot="dep" scope="props">
The <template>
element apparently does not support property binding. You can use <template>
with static properties, but using :slot
sets the "slot" property to null (and thus the component is never loaded)
Update: Scratch that... while changing it from <template>
to <div>
fixed the issue of a dynamic "slot" property, it broke the "scope" property. I wasn't able to access the row data. I guess this is just a limitation of VueJS at the moment
Update 2: I've created the following bug report for VueJS: https://github.com/vuejs/vue/issues/4951
I have data being returned from my API in the following format:
For each order, there's a list of departments. I wish to display the following using VueTable:
To make matters more confusing, this list of departments (and therefore fields to be displayed) is subject to change.
Worst-case scenario I can find a work-around by changing my API output to include "hasXXX" fields, however I would prefer to define my table with something like the following:
I could then create a single
has-department
component with adep
prop which tells it which department to search for.There may be an easier way to accomplish this that I just haven't thought of yet, but regardless I think there's value in being able to pass props to custom components.