ThingsBoard 仪表改造-改变仪表布局网格大小


有群友觉得:仪表板的格子太大了,有没有办法改小点,这样排放部件更精确,现在部件拖放的时候,要么太大要么太小!

自带修改

点击右下角进入编辑模式
image.png


空白处右键 -> 设置
image.png


增大列数就缩小单元格
image.png


列数50 部件间边距3 就很小了
image.png
根仪表板网格改小后,再增加的内仪表板的网格并没有改小,仍然是默认大小。通过改代码把默认网格大小改小,以后所有画面都是小网格很方便
感谢ThingBoard中文社区:BigG,刀刀 网友反馈


修改代码


image.pngimage.png
ui-ngx/src/app/modules/home/components/dashboard/dashboard.component.ts
添加有//custom-- 注释的代码,注释掉下面代码中注释掉的代码

ngOnInit(): void {
  if (!this.dashboardTimewindow) {
    this.dashboardTimewindow = this.timeService.defaultTimewindow();
  }
  this.gridsterOpts = {
  // gridType: GridType.ScrollVertical,
  // margin: isDefined(this.margin) ? this.margin : 3,
  gridType: GridType.Fixed, //custom--
  fixedColWidth: 30, //custom--
  fixedRowHeight: 30, //custom--
  margin: 3, //custom--
  
	//=====这下面的不用管,没有改动
  displayGrid:DisplayGrid.Always,//一直显示网格,方便演示,实际去掉这项
  swap: false, //打开后组件可交换位置
  maxRows: 100,//网格最大行数
  minCols: this.columns ? this.columns : 24,
  maxCols: 3000,//网格最大列数
  //仪表最大格子数
  maxItemCols: 1000,
  maxItemRows: 1000,
  maxItemArea: 1000000,
  outerMargin: true,
  minItemCols: 1,//仪表最小格子数
  minItemRows: 1,
  defaultItemCols: 8,//默认仪表格子数
  defaultItemRows: 6,
  resizable: {enabled: this.isEdit},
  draggable: {enabled: this.isEdit},
    //改变x,y,col,row时候的回调
    itemChangeCallback: item => this.dashboardWidgets.sortWidgets(),
      itemInitCallback: (item, itemComponent) => {
        (itemComponent.item as DashboardWidget).gridsterItemComponent = itemComponent;
      }
};

添加有//custom-- 注释的行,注释掉下面代码中注释的代码(自己都读不通这句话)

private updateMobileOpts(parentHeight?: number) {
    this.isMobileSize = this.checkIsMobileSize();
    const autofillHeight = this.isAutofillHeight();
    if (autofillHeight) {
      // this.gridsterOpts.gridType = this.isMobileSize ? GridType.Fixed : GridType.Fit;
      this.gridsterOpts.gridType = this.isMobileSize ? GridType.Fixed : GridType.Fixed; //custom--
    } else {
      // this.gridsterOpts.gridType = this.isMobileSize ? GridType.Fixed : GridType.ScrollVertical;
      this.gridsterOpts.gridType = this.isMobileSize ? GridType.Fixed : GridType.Fixed; //custom--
    }
    const mobileBreakPoint = this.isMobileSize ? 20000 : 0;
    this.gridsterOpts.mobileBreakpoint = mobileBreakPoint;
    if(this.isMobileSize){ //custom-- 加上是否是手机尺寸的判断,避免PC受影响
      const rowSize = this.detectRowSize(this.isMobileSize, autofillHeight, parentHeight);
      if (this.gridsterOpts.fixedRowHeight !== rowSize) {
        this.gridsterOpts.fixedRowHeight = rowSize;
      }
    } //custom--
  }

添加有//custom-- 注释的行,注释掉下面代码中注释的代码(自己都读不通这句话)

private updateLayoutOpts() {
  this.gridsterOpts.minCols = this.columns ? this.columns : 24;
  this.gridsterOpts.margin = 3; //custom--
  // this.gridsterOpts.margin = isDefined(this.margin) ? this.margin : 10;
}

说明

thingboard的格子布局使用的是angular-gridster2
下面的官网可以很好地调试出你要的效果。
如果觉得还不符合胃口,调整margin fixedColWidthfixedRowHeight
margin是网格中间的那个缝隙,根据fixedColWidthfixedRowHeight 的大小,相应设置大小。
gridType: GridType.ScrollVertical 网格类型如果选垂直滚动,是没办法调整网格大小的。


如果对你有帮助,点个赞关注一下吧


angular-gridster2官网地址
image.png

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

fool_dawei

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值