渐渐模糊了约定 2024-04-03 11:20 采纳率: 10.5%
浏览 23

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等。

    评论

报告相同问题?

问题事件

  • 创建了问题 4月3日

悬赏问题

  • ¥15 YOLOv8已有一个初步的检测模型,想利用这个模型对新的图片进行自动标注,生成labellmg可以识别的数据,再手动修改。如何操作?
  • ¥15 怎么做商品窗体,完完全全不会
  • ¥30 NIRfast软件使用指导
  • ¥20 matlab仿真问题,求功率谱密度
  • ¥15 求micropython modbus-RTU 从机的代码或库?
  • ¥15 铜与钢双金属板叠加在一起每种材料300mm长,18mm宽,4mm厚一端固定并加热至80℃,当加热端温度保持不变时另一端的稳态温度。ansys
  • ¥15 django5安装失败
  • ¥15 Java与Hbase相关问题
  • ¥15 后缀 crn 游戏文件提取资源
  • ¥20 bash代码推送不上去 git fetch origin master #失败了