vue table 加序号及列居中

该文描述了如何在Vue.js应用中使用ElementUI的el-table组件来创建带序号的表格,并实现数据分页。序号根据currentPage和pageSize动态计算,同时展示了如何设置单元格和表头内容居中对齐。此外,文中还包含了可切换状态的开关按钮操作。
摘要由CSDN通过智能技术生成

1.table加序号

序号列:

<el-table-column label="序号" type="index" width="60px">
	<template #default="scope">
		<span v-text="getIndex(scope.$index)"></span>
	</template>
</el-table-column>

state中封装的table分页信息:

       pagination: {
			currentPage: 0,
			pageSize: 10,
			total: 0
      }

获取序号的方法:

const getIndex = (index: number) => {
	return (state.pagination.currentPage - 1) * state.pagination.pageSize + index + 1;
}

列居中

 内容居中:     

:cell-style="{ textAlign: 'center' }"


表头居中

:header-cell-style="{textAlign: 'center'}" 

部分源代码如下:

        <el-table v-loading="tableData.loading" :data="tableData.data" style="width: 100%" 
				:cell-style="{ textAlign: 'center' }" 
				:header-cell-style="{textAlign: 'center'}" >
				
				<el-table-column label="序号" type="index" width="60px">
					<template #default="scope">
					<span v-text="getIndex(scope.$index)"></span>
					</template>
				</el-table-column>

				<el-table-column prop="jobClassName" label="任务执行类全限定名"   show-overflow-tooltip ></el-table-column>
				<el-table-column prop="jobName" label="task_name"   show-overflow-tooltip ></el-table-column>
				<el-table-column prop="group" label="task_group"   show-overflow-tooltip ></el-table-column>
				<el-table-column prop="triggerState" label="task_status" show-overflow-tooltip width="100px" ></el-table-column>
				<el-table-column prop="nextFireTime" label="task_next_firing_time"  show-overflow-tooltip ></el-table-column>
				
				<el-table-column prop="enableStatus" label="firing/pause task" width="150px">
					<template #default="scope">
						<span class="property-name-cell">
							<el-switch
								:value="scope.row.enableStatus"
								active-value="1"
								inactive-value="0"
								@change="pauseJob(scope.row.triggerState == 'PAUSED', scope.row)"
							/>
						</span>
					</template>
				</el-table-column>
				<el-table-column label="operations" width="150px">
					<template #default="scope">
						<el-button size="small" text type="primary" @click="immediatelyExecuteJobOneTime(scope.row)">execute_task_immediately</el-button>
						<el-button size="small" text type="primary" @click="onOpenInstace(scope.row)">taskInstances</el-button>
						<el-button size="small" text type="primary" @click="onOpenDetailQuartz(scope.row)">taskDetai</el-button>
						<el-button size="small" text type="primary" @click="onOpenEditQuartz(scope.row)">editTask</el-button>
						<el-button size="small" text type="primary" @click="onRowDelQuartz(scope.row)">deleteTask</el-button>
					</template>
				</el-table-column>
			</el-table>
            <el-pagination
				@size-change="onHandleSizeChange"
				@current-change="onHandleCurrentChange"
				class="mt15"
				:pager-count="5"
				:page-sizes="[10, 20, 30]"
				v-model:current-page="tableData.param.pageNum"
				background
				v-model:page-size="tableData.param.pageSize"
				layout="total, sizes, prev, pager, next, jumper"
				:total="tableData.total"
			>
			</el-pagination>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值