ANTDV-仅针对特定行显示扩展图标

发布于 2025-02-07 02:25:19 字数 3386 浏览 4 评论 0 原文

我正在使用ANTD进行VUE( antdv )版本1.7.8。

我想 例如,我只想向第二个条目显示展开图标(和funcionallity),该项目在项目 array中具有项目:

var Main = {
   data() {
      return {
         columns: [{
               title: 'ID',
               dataIndex: 'id',
            },
            {
               title: 'Name',
               dataIndex: 'name',
            },
            {
               title: 'Nº items',
               dataIndex: 'items',
               scopedSlots: {
                  customRender: 'items'
               },
            },

         ],
         tableData: [{
               "id": 1,
               "name": "Alex",
               "items": []
            },
            {
               "id": 2,
               "name": "Boris",
               "items": [{
                     "id": 1,
                     "name": "Don Quixote"
                  },
                  {
                     "id": 2,
                     "name": "Moby Dick"
                  }
               ]
            },
            {
               "id": 3,
               "name": "Carlos",
               "items": []
            }
         ]
      }
   }
}
var Ctor = Vue.extend(Main)
new Ctor().$mount('#app')
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.9/vue.js"></script>
<script src="https://unpkg.com/[email protected]/dist/vue.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/ant-design-vue/1.7.8/antd.min.js" integrity="sha512-o1PLXMVDD8r7lQlPXWHTyJxH7WpFm75dsSfzsa04HRgbeEHJv/EbaxEgACaB6mxbBmHU+Dl64MflqQB7cKAYpA==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>

<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/ant-design-vue/1.7.8/antd.css" integrity="sha512-Zl/2o30l4LayZodj2IuRoBhZLgQNvKnnSTwB08236BoPAhbhhS8dZltQfyftSVdEVrJ43uSyh/Keh1t/5yP5Ug==" crossorigin="anonymous" referrerpolicy="no-referrer" />

<div id="app">
  <template>
    <a-table
      :columns="columns"
      :row-key="record => record.id"
      :data-source="tableData"
      :pagination="{hideOnSinglePage:true}"
      :expand-icon-as-cell="false"
      :expand-icon-column-index="2"
      :expand-row-by-click="false"
    >
      <p slot="expandedRowRender" slot-scope="record">
        <template v-if="record.items.length === 0">
          Should not be rendered
        </template>
        <template v-else>
          An inner table with {{ record.items.length }} items.
        </template>
        
      </p>
      <template slot="items" slot-scope="items, record">
        {{ record.items.length }}
        <template v-if="record.items.length === 0">
          (&larr; Should not render expand button)
        </template>
      </template>
    </a-table>
  </template>
</div>

我该怎么做?

I am using antd for vue (antdv) version 1.7.8.

I would like to show expand icon only for rows that satisfy a given condition.
For example, I want to show expand icon (and funcionallity) only for second entry, which has items in items array:

var Main = {
   data() {
      return {
         columns: [{
               title: 'ID',
               dataIndex: 'id',
            },
            {
               title: 'Name',
               dataIndex: 'name',
            },
            {
               title: 'Nº items',
               dataIndex: 'items',
               scopedSlots: {
                  customRender: 'items'
               },
            },

         ],
         tableData: [{
               "id": 1,
               "name": "Alex",
               "items": []
            },
            {
               "id": 2,
               "name": "Boris",
               "items": [{
                     "id": 1,
                     "name": "Don Quixote"
                  },
                  {
                     "id": 2,
                     "name": "Moby Dick"
                  }
               ]
            },
            {
               "id": 3,
               "name": "Carlos",
               "items": []
            }
         ]
      }
   }
}
var Ctor = Vue.extend(Main)
new Ctor().$mount('#app')
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.9/vue.js"></script>
<script src="https://unpkg.com/[email protected]/dist/vue.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/ant-design-vue/1.7.8/antd.min.js" integrity="sha512-o1PLXMVDD8r7lQlPXWHTyJxH7WpFm75dsSfzsa04HRgbeEHJv/EbaxEgACaB6mxbBmHU+Dl64MflqQB7cKAYpA==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>

<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/ant-design-vue/1.7.8/antd.css" integrity="sha512-Zl/2o30l4LayZodj2IuRoBhZLgQNvKnnSTwB08236BoPAhbhhS8dZltQfyftSVdEVrJ43uSyh/Keh1t/5yP5Ug==" crossorigin="anonymous" referrerpolicy="no-referrer" />

<div id="app">
  <template>
    <a-table
      :columns="columns"
      :row-key="record => record.id"
      :data-source="tableData"
      :pagination="{hideOnSinglePage:true}"
      :expand-icon-as-cell="false"
      :expand-icon-column-index="2"
      :expand-row-by-click="false"
    >
      <p slot="expandedRowRender" slot-scope="record">
        <template v-if="record.items.length === 0">
          Should not be rendered
        </template>
        <template v-else>
          An inner table with {{ record.items.length }} items.
        </template>
        
      </p>
      <template slot="items" slot-scope="items, record">
        {{ record.items.length }}
        <template v-if="record.items.length === 0">
          (← Should not render expand button)
        </template>
      </template>
    </a-table>
  </template>
</div>

How can I do it?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

思念绕指尖 2025-02-14 02:25:19

在antdv v3中存在 roweppandable 参数。
在ANTDV V1中,您可以通过该行的自定义类完成:

:row-class-name="(record) => record.items.length > 0 ? 'show' : 'hide'"

您可以在此处看到一个示例: https://codesandbox.io/s/antdv2-rowexpandable-wgh7xz?file=/src/src/components/atable.vue

In Antdv v3 exist rowExpandable argument.
In Antdv v1 you can make it through a custom class for the row:

:row-class-name="(record) => record.items.length > 0 ? 'show' : 'hide'"

you can see an example here: https://codesandbox.io/s/antdv2-rowexpandable-wgh7xz?file=/src/components/aTable.vue

愚人国度 2025-02-14 02:25:19

您可以使用RowDatabound事件在儿童网格中没有记录时隐藏图标。
尝试以下所述的示例: https://ej2.syncfusion.com/vue/documentation/grid/how-to/hide-the-the-the-the-the-the--expand-collapse-icon-icon-icon-in-parent-row/ 一下

You can use rowDataBound event to hide the icon when there are no records in child grid.
Try the example as described here: https://ej2.syncfusion.com/vue/documentation/grid/how-to/hide-the-expand-collapse-icon-in-parent-row/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文