Search results

Floating Panels in React Dashboard Layout component

29 Nov 2022 / 1 minute to read

The floating functionality of the component allows you to effectively use the entire layout for the panel’s placement. If the floating functionality is enabled, the panels within the layout get floated upwards automatically to occupy the empty cells available in previous rows. This functionality can be enabled or disabled using the allowFloating property of the component.

The following sample demonstrates how to enable or disable the floating of panels in the Dashboard Layout component.

Source
Preview
App.jsx
index.jsx
index.html
App.css
App.tsx
index.tsx
Copied to clipboard
import { DashboardLayoutComponent } from '@syncfusion/ej2-react-layouts';
import * as React from 'react';
function App() {
    let dashboardObj;
    let buttonObj;
    let resetPanes = [];
    const cellSpacing = [10, 10];
    let panels = [
        { 'sizeX': 2, 'sizeY': 2, 'row': 1, 'col': 0, content: '<div class="content">0</div>' },
        { 'sizeX': 2, 'sizeY': 2, 'row': 2, 'col': 2, content: '<div class="content">1</div>' },
        { 'sizeX': 2, 'sizeY': 2, 'row': 3, 'col': 4, content: '<div class="content">2</div>' }
    ];
    // Button click action to change the floating options for DashboardLayout
    function onClick(args) {
        if (buttonObj.value === "Disable Floating and Reset") {
            buttonObj.value = 'Enable Floating';
            dashboardObj.allowFloating = false;
            dashboardObj.panels = resetPanes;
        }
        else {
            buttonObj.value = 'Disable Floating and Reset';
            dashboardObj.allowFloating = true;
        }
    }
    // Using created event to initialize the panels
    function onCreate(args) {
        resetPanes = dashboardObj.serialize();
        resetPanes[0].content = '<div class="content">0</div>';
        resetPanes[1].content = '<div class="content">1</div>';
        resetPanes[2].content = '<div class="content">2</div>';
    }
    return (<div>
          <div id='container'>
          <div className="inline" id="control">
              <DashboardLayoutComponent id='defaultLayout' ref={s => (dashboardObj = s)} cellSpacing={cellSpacing} created={onCreate} panels={panels} allowFloating={false} cellAspectRatio={100 / 75} columns={6}/>
          </div>
          <div className="inline" id="properties">
              <input type="button" ref={s => buttonObj = s} className="e-btn e-flat e-primary e-outline" name="floating" id="floating" value="Enable Floating" onClick={onClick}/>
          </div>
          </div>
      </div>);
}
export default App;
Copied to clipboard
import * as React from 'react';
import * as ReactDOM from 'react-dom';
import App from './App';
ReactDOM.render(<App />, document.getElementById('root'));
Copied to clipboard
<!DOCTYPE html>
<html lang="en">

<head>
    <title>Syncfusion EJ2 React Dashboard Layout Sample</title>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta name="description" content="Essential JS 2 for React Components" />
    <meta name="author" content="Syncfusion" />
    <link href="//cdn.syncfusion.com/ej2/20.3.56/ej2-base/styles/material.css" rel="stylesheet" />
    <link href="//cdn.syncfusion.com/ej2/20.3.56/ej2-buttons/styles/material.css" rel="stylesheet" />
    <link href="//cdn.syncfusion.com/ej2/20.3.56/ej2-react-layouts/styles/material.css" rel="stylesheet" />
    <script src="https://cdnjs.cloudflare.com/ajax/libs/systemjs/0.19.38/system.js"></script>
    <script src="systemjs.config.js"></script>
    <link rel="stylesheet" href="App.css">
</head>
<body>
    <div id='root'>
        <div id='loader'>Loading....</div>
    </div>  
</body>
</html>
Copied to clipboard
@import "../node_modules/@syncfusion/ej2-base/styles/material.css";
@import "../node_modules/@syncfusion/ej2-react-buttons/styles/material.css";
@import "../node_modules/@syncfusion/ej2-react-layouts/styles/material.css";

#container {
  margin: 0 auto;
  width: 600px;
}

.e-panel-container .content {
  vertical-align: middle;
  font-weight: 600;
  font-size: 20px;
  text-align: center;
  line-height: 90px;
}

div#properties {
  width: 205px;
  margin-left: 15px;
  padding: 15px;
  position: absolute;
}

.inline {
  display: inline-block;
}

div#control {
  width: 500px;
}
Copied to clipboard
import {  DashboardLayoutComponent } from '@syncfusion/ej2-react-layouts';
import * as React from 'react';

function App() {
  let dashboardObj: DashboardLayoutComponent;
  let buttonObj: any;
  let resetPanes : any = [];
  const cellSpacing: number[] = [10, 10];
  let panels: any =   [
      {'sizeX': 2, 'sizeY': 2, 'row': 1, 'col': 0, content:'<div class="content">0</div>'},
      {'sizeX': 2, 'sizeY': 2, 'row': 2, 'col': 2, content:'<div class="content">1</div>'},
      {'sizeX': 2, 'sizeY': 2, 'row': 3, 'col': 4, content:'<div class="content">2</div>'}
  ];
  // Button click action to change the floating options for DashboardLayout
  function onClick(args: any): void {
      if (buttonObj.value === "Disable Floating and Reset") {
          buttonObj.value = 'Enable Floating';
          dashboardObj.allowFloating = false;
          dashboardObj.panels = resetPanes;
      } else {
          buttonObj.value = 'Disable Floating and Reset';
          dashboardObj.allowFloating = true;
      }
  }

  // Using created event to initialize the panels
  function onCreate(args:any): void {
      resetPanes = dashboardObj.serialize();
      resetPanes[0].content = '<div class="content">0</div>';
      resetPanes[1].content = '<div class="content">1</div>';
      resetPanes[2].content = '<div class="content">2</div>';
  }
  return (
          <div>
          <div id='container'>
          <div className="inline" id="control">
              <DashboardLayoutComponent id='defaultLayout' ref={ s => (dashboardObj = s as DashboardLayoutComponent)} cellSpacing={cellSpacing} created= { onCreate } panels={panels} allowFloating={false} cellAspectRatio={100/75}  columns={6} />
          </div>
          <div className="inline" id="properties">
              <input type="button" ref={ s => buttonObj = s} className= "e-btn e-flat e-primary e-outline" name="floating" id="floating" value="Enable Floating" onClick={ onClick } />
          </div>
          </div>
      </div>
  );
}
export default App;
Copied to clipboard
import * as React from 'react';
import * as ReactDOM from 'react-dom';
import App  from './App';

ReactDOM.render(<App />, document.getElementById('root'));

You can refer to our React Dashboard Layout feature tour page for its groundbreaking feature representations. You can also explore our React Dashboard Layout example to knows how to present and manipulate data.