網站首頁 編程語言 正文
最近接到產品的一個需求,它是要對數據排序,實際操作中我們要實現表格行置頂置底上移下移操作。項目框架是GUNS框架。
如下圖:
我是怎么用Jquery+bootstrap進行實現這些功能的呢?往下看就知道了。
1.html
@layout("/common/_container.html"){? ?@}? ? ? ?? ? ? ? ? ?? ?? ? ? ? ? ? ? ? 報表管理>>報表版本>>配置指標 ? ? ? ? ? ?? ? ? ? ? ?? ? ? ? ? ? ? ?? ? ? ?? ? ? ? ? ? ? ? ? ?? ? ? ? ? ?? ? ? ? ? ? ? ? ? ? ? ?? ? ? ? ? ? ? ?? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?? ? ? ? ? ? ? ? ? ? ? ?? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? <#NameCon id="condition" name="名稱" /> ? ? ? ? ? ? ? ? ? ? ? ? ? ?? ? ? ? ? ? ? ? ? ? ? ? ? ?? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? <#button name="搜索" icon="fa-search" clickFun="QuotaVer.search()"/> ? ? ? ? ? ? ? ? ? ? ? ? ? ?? ? ? ? ? ? ? ? ? ? ? ?? ? ? ? ? ? ? ? ? ? ? ? ? ? @if(shiro.hasPermission("/quotaVer/addIndex")){ ? ? ? ? ? ? ? ? ? ? ? ? ? ? <#button name="添加指標" icon="fa-plus" clickFun="QuotaVer.openAddQuota()"/> ? ? ? ? ? ? ? ? ? ? ? ? ? ? @} ? ? ? ? ? ? ? ? ? ? ? ? ? ? @if(shiro.hasPermission("/quotaVer/save")){ ? ? ? ? ? ? ? ? ? ? ? ? ? ? <#button name="保存數據" icon="fa-plus" clickFun="QuotaVer.saveQuotaVer()"/> ? ? ? ? ? ? ? ? ? ? ? ? ? ? @} ? ? ? ? ? ? ? ? ? ? ? ?? ? ? ? ? ? ? ? ? ? ? ? <#table id="QuotaVerTable"/> ? ? ? ? ? ? ? ? ? ?
注意:這里使用的是GUNS框架,所以代碼風格跟一般的html寫法稍有不同。
2.JS代碼
{title: '操作', visible: true, align: 'center', valign: 'middle',events: operateEvents, ? ? ? ? ? ? ? ? formatter: operateFormatter}
function operateFormatter(value, row, index) { ? ? return [ ? ? ? ? '', ? ? ? ? '上移', ? ? ? ? ' ?', ? ? ? ? '', ? ? ? ? '下移', ? ? ? ? ' ?', ? ? ? ? '', ? ? ? ? '刪除', ? ? ? ? ' ?', ? ? ].join('') }
window.operateEvents = { ? ? 'click .up': function (e, value, row, index) { ? ? ? ? //點擊上移 ? ? ? ? var $tr = $(this).parents("tr"); ? ? ? ? if ($tr.index() == 0){ ? ? ? ? ? ? Feng.success("首行數據不可上移!"); ? ? ? ? }else{ ? ? ? ? ? ? $tr.fadeOut().fadeIn(); ? ? ? ? ? ? //交換后臺數組數據 ? ? ? ? ? ? var array = $('#QuotaVerTable').bootstrapTable('getData'); ? ? ? ? ? ? //行在table中的位置 ? ? ? ? ? ? var idx = $tr.index(); ? ? ? ? ? ? //交換元素 ? ? ? ? ? ? var temp = array[idx]; ? ? ? ? ? ? array[idx] = array[idx - 1]; ? ? ? ? ? ? array[idx - 1] = temp; ? ? ? ? ? ? $tr.prev().before($tr); ? ? ? ? } ? ? }, ? ? 'click .down': function (e, value, row, index) { ? ? ? ? //點擊下移 ? ? ? ? var $tr = $(this).parents("tr"); ? ? ? ? //獲取table所有數據行 ?QuotaVerTable跟html頁面的table id對應 ? ? ? ? var len = $('#QuotaVerTable').bootstrapTable('getData').length; ? ? ? ? if ($tr.index() == len - 1) { ? ? ? ? ? ? Feng.success("尾行數據不可下移!"); ? ? ? ? }else { ? ? ? ? ? ? $tr.fadeOut().fadeIn(); ? ? ? ? ? ? //交換后臺數組數據 ? ? ? ? ? ? var array = $('#QuotaVerTable').bootstrapTable('getData'); ? ? ? ? ? ? //行在table中的位置 ? ? ? ? ? ? var idx = $tr.index(); ? ? ? ? ? ? //交換元素 ? ? ? ? ? ? var temp = array[idx]; ? ? ? ? ? ? array[idx] = array[idx + 1]; ? ? ? ? ? ? array[idx + 1] = temp; ? ? ? ? ? ? $tr.next().after($tr); ? ? ? ? } ? ? } }
在實現上移下移的同時,做了數據的順序交換。
原文鏈接:https://blog.csdn.net/weixin_42590334/article/details/93593357
相關推薦
- 2022-03-27 MongoDB4.28開啟權限認證配置用戶密碼登錄功能_MongoDB
- 2022-05-08 Python?matplotlib繪制xkcd動漫風格的圖表_python
- 2022-05-08 Python?matplotlib實現散點圖的繪制_python
- 2023-07-03 前端面試中遇到的垂直居中問題
- 2022-06-08 Spring源碼之Bean的掃描以及創建
- 2024-04-08 Spring在多線程環境下如何確保事務一致性
- 2023-06-18 C#?指針內存控制Marshal內存數據存儲原理分析_C#教程
- 2022-04-12 如何解決git上傳文件出錯 [rejected] cjp -> cjp (fetch first)e
- 最近更新
-
- window11 系統安裝 yarn
- 超詳細win安裝深度學習環境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區別,Jav
- spring @retryable不生效的一種
- Spring Security之認證信息的處理
- Spring Security之認證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權
- redisson分布式鎖中waittime的設
- maven:解決release錯誤:Artif
- restTemplate使用總結
- Spring Security之安全異常處理
- MybatisPlus優雅實現加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務發現-Nac
- Spring Security之基于HttpR
- Redis 底層數據結構-簡單動態字符串(SD
- arthas操作spring被代理目標對象命令
- Spring中的單例模式應用詳解
- 聊聊消息隊列,發送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠程分支