v7.3.0
SupportExamplesFree Trial

GridResponsive
Mixin

Simplifies making grid responsive. Supply levels as responsiveLevels config, default levels are:

small
< 400px
medium
< 600px
large
> 600px

Columns can define configs per level to be resized etc:

let grid = new Grid({
  responsiveLevels: {
    small: 300,
    medium: 400,
    large: '*' // everything above 400
  },

columns: [ { field: 'name', text: 'Name', responsiveLevels: { small: { hidden: true }, '*': { hidden: false } // all other levels } }, { field: 'xx', ... } ] });

It is also possible to give a Grid state object instead of a level width, but in that case the object must contain a levelWidth property:

let grid = new Grid({
  responsiveLevels: {
    small: {
      // Width is required
      levelWidth : 400,
      // Other configs are optional, see GridState for available options
      rowHeight  : 30
    },
    medium : {
      levelWidth : 600,
      rowHeight  : 40
    },
    large: {
      levelWidth : '*', // everything above 300
      rowHeight  : 45
    }
  }
});

targetElement.innerHTML = ` <p>Drag the slider to resize it and see GridResponsive in action. <br>Current level: <span id="responsive-level"></span></p> <div id="responsive-container"></div>`; targetElement.style.justifyContent = 'flex-start'; targetElement = targetElement.querySelector('#responsive-container'); //START // grid with cell editing const grid = new Grid({ appendTo : targetElement, width : 600, // makes grid as high as it needs to be to fit rows autoHeight : true, data : DataGenerator.generateData(5), responsiveLevels : { small : { // Width is required levelWidth : 400, // Other configs are optional, see GridState for available options rowHeight : 30 }, medium : { levelWidth : 600, rowHeight : 40 }, large : { levelWidth : '*', // everything above 300 rowHeight : 45 } }, columns : [ { field : 'name', text : 'Name', flex : 1 }, { field : 'team', text : 'Team', flex : 1 }, { field : 'score', text : 'Score', responsiveLevels : { '*' : { flex : 1, hidden : false }, medium : { flex : 0.5, hidden : false }, small : { hidden : true } } }, { field : 'rank', text : 'Rank', flex : 1, responsiveLevels : { '*' : { flex : 1, hidden : false }, medium : { flex : 0.5, hidden : false }, small : { hidden : true } } } ] }); //END const slider = new Slider({ insertFirst : targetElement, min : 200, max : 700, value : 600, width : 200, showValue : false, style : 'margin-bottom: 1em', onInput() { grid.element.style.width = this.value + 'px'; } }); function updateCurrentLevel() { const el = document.getElementById('responsive-level'); if (el) { el.innerHTML = `<b>${grid.responsiveLevel}</b>`; } } updateCurrentLevel(); grid.on({ responsive : () => updateCurrentLevel() });

See also

  • Grid - The Grid widget
  • Column - Column configuration
No results

Configs

Configs are options you supply in a configuration object when creating an instance of this class

Properties

Properties are getters/setters or publicly accessible variables on this class

Functions

Functions are methods available for calling on the class
    • Find closes bigger level, aka level we want to use.

    Events

    Events are triggered for certain actions in this class and can be listened for to react to those actions in your code

    Event handlers

    Event handlers are callbacks called as a result of certain actions in this class

    Type definitions

    Source path

    Grid/view/mixin/GridResponsive.js

    Demo

    examples/responsive

    Contents