首页 > 解决方案 > react-grid layout html不更新cols

问题描述

我使用反应网格布局:https ://github.com/react-grid-layout/react-grid-layout

我不明白为什么我的表格中的列数没有通过网络浏览器更新。

事实上,this.props.cols.lg 不是 17 就是 24。

当它是 17 时,我的表正确显示。另一方面,当我选择一个有 24 列的时间段时,我的列从第 18 列开始依次排列。

this.props.cols.lg 设置为正确的值(17 或 24),但我的 HTML 页面没有更新到设计级别。

这是单行上的正确表格:

在此处输入图像描述

右表

如您所见,firefox web 控制台显示 react 属性与 17 一致:

在此处输入图像描述

和坏桌子

在此处输入图像描述

坏表

在这里,firefox web 控制台再次显示反应属性是正确的 (24),但没有被 web 浏览器应用:

在此处输入图像描述

重要信息,

this.props.cols.lg=loopValue+1; **contains the right value (17 or 24) but apply on 17**

预先感谢您的帮助。

这是我的代码的一部分:

import React, { useState, useEffect, Fragment } from 'react';
import { WidthProvider, Responsive } from "react-grid-layout";
import ReactTooltip from 'react-tooltip';
import _ from "lodash";
import { Button, Container } from 'react-bootstrap';
const ResponsiveReactGridLayout = WidthProvider(Responsive);
import { Responsive as ResponsiveGridLayout } from 'react-grid-layout';
/**
 * This layout demonstrates how to use a grid with a dynamic number of elements.
 */
export class AddRemoveLayout extends React.PureComponent {
    //les propriétés par défaut
    static defaultProps = {
        className: "layout border-darken-1 child-background-color",
        cols:
        { lg: 10, md: 10, sm: 10, xs: 10, xxs: 10 },
        width: 1000,
        margin: [0, 0],
        preventCollision: true,
        autoSize: true,
      //  preventCollision: true,
        rowHeight: 70,

    // Build HTML to insert
    render() {


        //Week
        let createDateItem =
            (x, y, day) => ({
                i: `date-${x}_${y}`,
                x,
                y,
                w: 1,
                h: 1,
                myText: `${day}` ,
                static: true
            });
        /**
         *
         * @param {*} y
         * @param {*} xStart
         * @param {num semaine} dateStart
         * @param {nombre semaine total} count
         */

        let getDateItems =
            (y, xStart, dateStart, count,dateEnd) => {
                let items = [];

                let loopValue = 0;

                while(dateStart<=dateEnd){//semainee
                    if(loopValue>1){
                        dateStart.setDate(dateStart.getDate() + 7)
                    }
                    if(dateStart<=dateEnd){
                    items.push(
                        createDateItem(xStart + loopValue, y,  loopValue === 0 ? 0 :
                           (dateStart.getDate()+"/" +(dateStart.getUTCMonth()+1)+ " (Sem. "+loopValue +") ")
                        ))
                    }
                    loopValue++;
                }

               console.log('props:')
               console.log(this.props);
               this.props.cols.lg=loopValue+1;
               this.props.cols.md=loopValue+1;
               this.props.cols.sm=loopValue+1;
               this.props.cols.xs=loopValue+1;
               this.props.cols.xxsloopValue+1;
               console.log(this.props);

               // console.log(AddRemoveLayout.defaultProps)

                return items;
            }
            ;
    

标签: reactjslaraveltwitter-bootstrapreact-grid-layout

解决方案


我们找到了解决方案:

data: { idHoraire: 1 },

它总是发送到 PHP 的同一个项目,使用这段代码,我对我的 cols 有很好的显示,因为我要么发送 1 (17 cols) 要么 2 (25 cols) :

data: { idHoraire: url === "index2" ?2 : 1, },

推荐阅读