Ant Design Vue 表单组件table之 <s-table>

本文介绍了Ant Design Vue中的s-table组件,该组件在使用上简化了分页处理,只需后端返回相应参数即可。查询功能通过设置queryParam与columns对应字段匹配实现,排序功能通过传递sortField和sortOrder参数给后端进行数据排序。此外,文章还展示了s-table的查询、排序和分页配置示例代码。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

代码如下:

    # 查询条件
    <a-form layout="inline">
      <a-row :gutter="48">
        <template v-if="advanced">
          <a-col :md="8" :sm="24">
             <a-form-item label="id">
               <a-input v-model="queryParam.id" allow-clear style="width: 100%"/>
             </a-form-item>
           </a-col>
       	  <a-col :md="8" :sm="24">
            <a-form-item label="日期">
             <a-range-picker v-model="queryParam.updateTime" showTime format="YYYY-MM-DD HH:mm:ss" style="width: 100%" placeholder="请输入日期"/>
       	    </a-form-item>
          </a-col>
           <a-col :md="8" :sm="24">
                <a-form-item label="类型">
                  <a-select v-model="queryParam.do" placeholder="请选择" default-value="0">
                    <a-select-option value="">全部</a-select-option>
                    <a-select-option value="0">是</a-select-option>
                    <a-select-option value="1">否</a-select-option>
                  </a-select>
                </a-form-item>
             </a-col>
         </template>
     <a-col :md="!advanced && 8 || 24" :sm="24">
       <span class="table-page-search-submitButtons" :style="advanced && { float: 'right', overflow: 'hidden' } || {} ">
           <a-button type="primary" @click="$refs.table.refresh(true)">查询</a-button>
       </span>
      </a-col>
    </a-row>
   </a-form>
<template>
  <s-table
    ref="table"
    size="default"
    :columns="columns"
    :data="loadData"
  >
  </s-table>
</template>

<script>
  import { STable } from '@/components'
  # 分装的方法
  import { getUserList } from '@/api/user'
  export default {
    components: {
      STable
    },
    data() {
      return {
        columns: [
          {
            title: 'id',
            align: 'center',
            dataIndex: 'id'
          },
          {
            title: '名称',
            align: 'center',
            dataIndex: 'name'
          },
          {
            title: '状态',
            align: 'center',
            dataIndex: 'status',
          },
          {
            title: '更新时间',
            align: 'center',
            dataIndex: 'updateTime',
            sorter: true
          }
        ],
        // 查询条件参数
        queryParam: {},
        // 加载数据方法 必须为 Promise 对象
        loadData: parameter => {
          const requestParameters = Object.assign({}, parameter, this.queryParam)
          return getUserList(requestParameters)
          .then(res => {
            console.log(res)
            return res.data
          })
        }
      }
    }
  }
</script>

介绍

  1. s-table 和 官网的 a-table相比,目前发现,就是不用处理分页,只要后端返回相应参数即可。
  2. 查询,只要确保 queryParam的属性和columns中对应的字段一致即可。
  3. 排序,s-table 表单的排序,会向后端传输两个参数,sortField与sortOrder。sortField代表排序的字段,sortOrder代表是升序还是降序,如下是升序。分页传的参数为 pageNo和pagesize。 如下:在这里插入图片描述
  4. 后台传回来的参数格式,包括四个分页需要用到的参数,如下:在这里插入图片描述
您可以在 Ant Design Vue 的弹窗中使用 Table 组件和 Select 组件来实现行编辑中的下拉选择框。首先,您需要在 Table 组件中设置 editable 属性为 true,这样就可以开启行编辑功能。然后,您可以在需要进行下拉选择框编辑的列中,使用 scoped slot 的方式自定义单元格内容,并在该单元格中使用 Select 组件来实现下拉选择框。具体实现方法可以参考以下代码示例: ```html <template> <div> <a-button type="primary" @click="showModal">打开弹窗</a-button> <a-modal v-model="visible" title="编辑表格" :width="800"> <a-form :form="form"> <a-table :columns="columns" :data-source="data" :row-key="record => record.id" :editable="true"> <template slot-scope="text, record, index"> <a-form-item> <a-select v-model="record.selectValue" style="width: 100%"> <a-select-option v-for="option in options" :key="option.value" :value="option.value">{{ option.label }}</a-select-option> </a-select> </a-form-item> </template> </a-table> </a-form> </a-modal> </div> </template> <script> import { Modal, Form, Button, Table, Select } from 'ant-design-vue' export default { components: { 'a-modal': Modal, 'a-form': Form, 'a-button': Button, 'a-table': Table, 'a-form-item': Form.Item, 'a-select': Select, 'a-select-option': Select.Option, }, data() { return { visible: false, form: this.$form.createForm(this), data: [ { id: 1, name: '张三', age: 18, selectValue: 'option1' }, { id: 2, name: '李四', age: 22, selectValue: 'option2' }, { id: 3, name: '王五', age: 25, selectValue: 'option3' }, ], options: [ { label: '选项1', value: 'option1' }, { label: '选项2', value: 'option2' }, { label: '选项3', value: 'option3' }, ], columns: [ { title: 'ID', key: 'id', dataIndex: 'id', editable: false }, { title: '姓名', key: 'name', dataIndex: 'name', editable: true }, { title: '年龄', key: 'age', dataIndex: 'age', editable: true }, { title: '下拉选择框', key: 'selectValue', dataIndex: 'selectValue', editable: true }, ], } }, methods: { showModal() { this.visible = true }, }, } </script> ``` 在上面的代码示例中,我们使用了 Ant Design Vue 的 Modal、Form、Button、Table 和 Select 组件来实现弹窗、表单、按钮、表格和下拉选择框。在 Table 组件中,我们使用了 scoped slot 来自定义单元格内容,并在该单元格中使用 Select 组件来实现下拉选择框。同时,我们还需要在该列的配置项中设置 editable 属性为 true,以开启该列的编辑功能。最终,我们将 Table 组件放置在 Modal 组件中,实现了在弹窗中编辑带有下拉选择框的表格的功能。
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值