渐渐模糊了约定 2024-04-03 11:20 采纳率: 17.4%
浏览 39
已结题

layui table表头与列不对齐

使用的layui.table
帮忙看一下为什么我的列对不齐:

img


```javascript
table.render({
                        elem: '#add'
                        ,id: 'tab2'
                        // , height: ''
                        , url: 'views/pda/Cld_SltJson_wj'
                        , where: { where: "", order: "FBILLNO",name:"V_PoorderCount",page:page+1}
                        // ,height: alarmTableContainer.height() - 16
                        , totalRow: false
                        , cols: [[ //标题栏
                             { field: 'FBillNo', minWidth: 100, title: '订单编号', align: 'center' }
                            , { field: 'FDate', minWidth: 100, title: '订单日期', align: 'center' }
                            , { field: 'FCustName', minWidth: 120, title: '供应商', align: 'center' }
                            , { field: 'FMaterialNumber', minWidth: 200, title: '物料编码', align: 'center' }
                            , { field: 'FMaterialName', minWidth: 80, title: '物料名称', align: 'center' }
                            , { field: 'FMaterialModel', minWidth: 80, title: '规格型号', align: 'center' }
                            , { field: 'FQty', minWidth: 80, title: '订货数量', align: 'center' }
                            , { field: 'FProdDate', minWidth: 80, title: '订单交货日期', align: 'center' }
                            , { field: 'FInStockQty', minWidth: 80, title: '收料数量', align: 'center' }
                            , { field: 'FStockQty', minWidth: 80, title: '入库数量', align: 'center' }
                            , { field: 'FOutStockQty', minWidth: 100, title: '剩余入库数量', align: 'center' }
                        ]]
                        , skin: 'row' //表格风格
                        , even: true
                        , size: 'md'
                        , page: {  //支持传入 laypage 组件的所有参数(某些参数除外,如:jump/elem) - 详见文档
                            layout: ['limit', 'count', 'prev', 'page', 'next'] //自定义分页布局
                        }
                        , limit: 3 //每页默认显示的数量    
                        // , limits: [200, 500]
                        , page: false
                        , done: function (res, curr, count) {
                            

                            //定位当前table视图
                            var that = this.elem.next();
                            res.data.forEach(function (item, index) {
                                // 所需的条件
                                if (item.FColour == 1) { //1=黑色
                                    that.find('tbody tr[data-index="' + index + '"]')
                                        .css('background-color', '#070707') //背景颜色
                                        .css('color', '#f7faf6')            //字体颜色
                                        .css('border', '1px solid #FFF');   //边框
                                } else if (item.FSEQ <= 1) {//2=红色                              
                                    that.find('tbody tr[data-index="' + index + '"]').css('background-color', '#f60303').css('color', '#070707').css('border', '1px solid #FFF');
                                } else if (item.FSEQ <= 3 && item.FSEQ > 1) {//3=黄色
                                    that.find('tbody tr[data-index="' + index + '"]').css('background-color', '#f8f804').css('color', '#0b0b0b').css('border', '1px solid #FFF');
                                } else if (item.FColour == 4) {//4=绿色
                                    that.find('tbody tr[data-index="' + index + '"]').css('background-color', '#2df804').css('color', '#0b0b0b').css('border', '1px solid #FFF');
                                } else {
                                    that.find('tbody tr[data-index="' + index + '"]').css('background-color', '#f7faf6').css('color', '#101010').css('border', '1px solid #070707');
                                }
                            });
                            //response.data获取后端返回的JSON格式数据
                            $.each(res.data, function (index, item) {
                            })
                            //数据渲染完的回调
                        }
                    })


  • 写回答

3条回答 默认 最新

  • 码农阿豪@新空间代码工作室 Java领域优质创作者 2024-04-03 11:20
    关注
    让阿豪来帮你解答,本回答参考chatgpt3.5编写提供,如果还有疑问可以评论或留言
    问题:为什么我的列对不齐? 解答:这个问题的原因可能是由于表格中的某些单元格内容超出了列宽,导致整个表格的列对不齐。可以通过设置列的宽度、自适应宽度或优化表格内容来解决这个问题。 案例: 以下是使用layui.table的一个简单示例,用于展示如何使用列宽度和自适应宽度来解决列对齐问题:
    // 设置列宽度
    , cols: [[
      { field: 'id', width: 80, title: 'ID', align: 'center' }
      , { field: 'username', width: 120, title: '用户名', align: 'center' }
      , { field: 'phone', width: 150, title: '手机号码', align: 'center' }
      , { field: 'email', width: 250, title: '电子邮件', align: 'center' }
      , { field: 'address', minWidth: 200, title: '地址', align: 'center' }
    ]]
    // 自适应宽度
    , cols: [[
      { field: 'id', title: 'ID', align: 'center' }
      , { field: 'username', title: '用户名', align: 'center' }
      , { field: 'phone', title: '手机号码', align: 'center' }
      , { field: 'email', title: '电子邮件', align: 'center' }
      , { field: 'address', title: '地址', align: 'center' }
    ]]
    

    在设置列宽度时,可以使用width属性来指定具体的宽度值;而在自适应宽度的情况下,可以省略width属性,layui.table会自动根据单元格内容的宽度自适应。 除此之外,还可以考虑优化表格内容,例如缩短较长的文本、使用省略号等,以使表格更加美观和易读。 代码示例:

    <table class="layui-table" id="demo" lay-filter="demo"></table>
    <script>
      var table = layui.table;
      //第一个实例
      table.render({
        elem: '#demo'
        ,height: 315
        ,url: '/demo/table/user/' //数据接口
        ,page: true //开启分页
        ,cols: [[ //表头
          {field: 'id', title: 'ID', width:80, sort: true, fixed: 'left', align: 'center'}
          ,{field: 'username', title: '用户名', width:120,align: 'center'}
          ,{field: 'sex', title: '性别', width:80, sort: true,align: 'center'}
          ,{field: 'city', title: '城市', width:100,align: 'center'}
          ,{field: 'sign', title: '签名', width: 200,align: 'center'}
          ,{field: 'experience', title: '积分', width: 80, sort: true,align: 'center'}
          ,{field: 'score', title: '评分', width: 80, sort: true,align: 'center'}
          ,{field: 'classify', title: '职业', width: 100,align: 'center'}
          ,{field: 'wealth', title: '财富', width: 135, sort: true,align: 'center'}
        ]]
      });
    </script>
    

    注意:这只是一个示例代码,要根据实际需要修改具体参数,例如URL、cols等。

    评论

报告相同问题?

问题事件

  • 已结题 (查看结题原因) 7月30日
  • 创建了问题 4月3日

悬赏问题

  • ¥15 如何在vue.config.js中读取到public文件夹下window.APP_CONFIG.API_BASE_URL的值
  • ¥50 浦育平台scratch图形化编程
  • ¥20 求这个的原理图 只要原理图
  • ¥15 vue2项目中,如何配置环境,可以在打完包之后修改请求的服务器地址
  • ¥20 微信的店铺小程序如何修改背景图
  • ¥15 UE5.1局部变量对蓝图不可见
  • ¥15 一共有五道问题关于整数幂的运算还有房间号码 还有网络密码的解答?(语言-python)
  • ¥20 sentry如何捕获上传Android ndk 崩溃
  • ¥15 在做logistic回归模型限制性立方条图时候,不能出完整图的困难
  • ¥15 G0系列单片机HAL库中景园gc9307液晶驱动芯片无法使用硬件SPI+DMA驱动,如何解决?