Skip to content
LIBRARYLayout

Grid ​

Included in alpha.11. MGrid lays out equal-width columns on Vue Web and NativeScript. It keeps keyed children mounted when columns change.

Web preview
Open example ↗
vue
<m-grid :columns="3" :min-column-width="180" gap="md">
  <m-card v-for="item in items" :key="item.id">{{ item.title }}</m-card>
</m-grid>
PropTypeDefaultPurpose
columnspositive integer—Fixed column count; maximum when minColumnWidth is set.
minColumnWidthpositive number—Desired minimum cell width in CSS pixels on Web or DIPs on NativeScript.
gapspacing token / numbernoneEqual horizontal and vertical spacing.
columnSpan (on a child)positive integer1Columns the child takes, at most the columns there are. A child that does not fit in what is left of the row starts the next one.

Without either sizing prop, the grid has one column. With minColumnWidth, the count follows the content width after padding and gaps, with at least one column. A container narrower than the requested minimum uses one cell that fits the available width. columns caps the adaptive count. Common Box props such as width, padding and backgroundColor also apply.

SSR and the first hydration render use columns, or one column when omitted. Width measurement updates the layout afterward without replacing keyed editors. Web uses CSS Grid; NativeScript uses a GridLayout with equal star columns and auto-height rows. Keep stable keys on collection children. This is a mounted grid, without virtualization or masonry placement.

vue
<script setup lang="ts">
import { ref } from 'vue'
import { useCatalogLocale } from '../locale'
const { locale } = useCatalogLocale()
const draft = ref('')
</script>
<template>
  <m-grid :columns="3" :min-column-width="180" gap="md">
    <m-card
      v-for="number in 4"
      :key="number"
      :columnSpan="number === 1 || number === 4 ? 2 : undefined"
      padding="md"
    >
      <m-text variant="heading">{{ locale === 'pt' ? 'Ideia' : 'Idea' }} {{ number }}</m-text>
      <m-input
        v-if="number === 1"
        v-model="draft"
        :label="locale === 'pt' ? 'Seu rascunho' : 'Your draft'"
      />
      <m-text v-else>{{ locale === 'pt' ? 'Espaço para criar.' : 'Room to create.' }}</m-text>
    </m-card>
  </m-grid>
</template>

Components for NativeScript and Web. Starting with Vue.