当前位置:Gxlcms > PHP教程 > javascript-Yii2表格缩放列宽,页面刷新后保持不变怎么实现?

javascript-Yii2表格缩放列宽,页面刷新后保持不变怎么实现?

时间:2021-07-01 10:21:17 帮助过:26人阅读

1、Yii2 DynaGrid插件生成的列表可以手动拖动每一列的宽度,但是拖动之后怎么保存?使刷新页面后还是刚才拖动停止的宽度。

主要代码如下:(由rc-table-resizing与rc-column-resizing这两class控制)

注释:以下是源码,不能改动,要重写。

  1. <code> ResizableColumns.prototype.pointerdown = function(e) {
  2. var $currentGrip, $leftColumn, $ownerDocument, $rightColumn, newWidths, startPosition, widths;
  3. e.preventDefault();
  4. $ownerDocument = $(e.currentTarget.ownerDocument);
  5. startPosition = pointerX(e);
  6. $currentGrip = $(e.currentTarget);
  7. $leftColumn = $currentGrip.data('th');
  8. $rightColumn = this.$tableHeaders.eq(this.$tableHeaders.index($leftColumn) + 1);
  9. widths = {
  10. left: parseWidth($leftColumn[0]),
  11. right: parseWidth($rightColumn[0])
  12. };
  13. newWidths = {
  14. left: widths.left,
  15. right: widths.right
  16. };
  17. this.$handleContainer.add(this.$table).addClass('rc-table-resizing');
  18. $leftColumn.add($rightColumn).add($currentGrip).addClass('rc-column-resizing');
  19. this.triggerEvent('column:resize:start', [$leftColumn, $rightColumn, newWidths.left, newWidths.right], e);
  20. $ownerDocument.on('mousemove.rc touchmove.rc', (function(_this) {
  21. return function(e) {
  22. var difference;
  23. difference = (pointerX(e) - startPosition) / _this.$table.width() * 100;
  24. setWidth($leftColumn[0], newWidths.left = _this.constrainWidth(widths.left + difference));
  25. setWidth($rightColumn[0], newWidths.right = _this.constrainWidth(widths.right - difference));
  26. if (_this.options.syncHandlers != null) {
  27. _this.syncHandleWidths();
  28. }
  29. return _this.triggerEvent('column:resize', [$leftColumn, $rightColumn, newWidths.left, newWidths.right], e);
  30. };
  31. })(this));
  32. return $ownerDocument.one('mouseup touchend', (function(_this) {
  33. return function() {
  34. $ownerDocument.off('mousemove.rc touchmove.rc');
  35. _this.$handleContainer.add(_this.$table).removeClass('rc-table-resizing');
  36. $leftColumn.add($rightColumn).add($currentGrip).removeClass('rc-column-resizing');
  37. _this.syncHandleWidths();
  38. _this.saveColumnWidths();
  39. return _this.triggerEvent('column:resize:stop', [$leftColumn, $rightColumn, newWidths.left, newWidths.right], e);
  40. };
  41. })(this));
  42. };
  43. return ResizableColumns;
  44. })();</code>

回复内容:

1、Yii2 DynaGrid插件生成的列表可以手动拖动每一列的宽度,但是拖动之后怎么保存?使刷新页面后还是刚才拖动停止的宽度。

主要代码如下:(由rc-table-resizing与rc-column-resizing这两class控制)

注释:以下是源码,不能改动,要重写。

  1. <code> ResizableColumns.prototype.pointerdown = function(e) {
  2. var $currentGrip, $leftColumn, $ownerDocument, $rightColumn, newWidths, startPosition, widths;
  3. e.preventDefault();
  4. $ownerDocument = $(e.currentTarget.ownerDocument);
  5. startPosition = pointerX(e);
  6. $currentGrip = $(e.currentTarget);
  7. $leftColumn = $currentGrip.data('th');
  8. $rightColumn = this.$tableHeaders.eq(this.$tableHeaders.index($leftColumn) + 1);
  9. widths = {
  10. left: parseWidth($leftColumn[0]),
  11. right: parseWidth($rightColumn[0])
  12. };
  13. newWidths = {
  14. left: widths.left,
  15. right: widths.right
  16. };
  17. this.$handleContainer.add(this.$table).addClass('rc-table-resizing');
  18. $leftColumn.add($rightColumn).add($currentGrip).addClass('rc-column-resizing');
  19. this.triggerEvent('column:resize:start', [$leftColumn, $rightColumn, newWidths.left, newWidths.right], e);
  20. $ownerDocument.on('mousemove.rc touchmove.rc', (function(_this) {
  21. return function(e) {
  22. var difference;
  23. difference = (pointerX(e) - startPosition) / _this.$table.width() * 100;
  24. setWidth($leftColumn[0], newWidths.left = _this.constrainWidth(widths.left + difference));
  25. setWidth($rightColumn[0], newWidths.right = _this.constrainWidth(widths.right - difference));
  26. if (_this.options.syncHandlers != null) {
  27. _this.syncHandleWidths();
  28. }
  29. return _this.triggerEvent('column:resize', [$leftColumn, $rightColumn, newWidths.left, newWidths.right], e);
  30. };
  31. })(this));
  32. return $ownerDocument.one('mouseup touchend', (function(_this) {
  33. return function() {
  34. $ownerDocument.off('mousemove.rc touchmove.rc');
  35. _this.$handleContainer.add(_this.$table).removeClass('rc-table-resizing');
  36. $leftColumn.add($rightColumn).add($currentGrip).removeClass('rc-column-resizing');
  37. _this.syncHandleWidths();
  38. _this.saveColumnWidths();
  39. return _this.triggerEvent('column:resize:stop', [$leftColumn, $rightColumn, newWidths.left, newWidths.right], e);
  40. };
  41. })(this));
  42. };
  43. return ResizableColumns;
  44. })();</code>

这是css控制的,你可以设置一个session,保存下你的列表的宽度,刷新的时候,就可以用js赋值给css就可以了。

楼上说的没错呢

人气教程排行