Grid Conditional Row Selection

Grid for Vue

Vue 3 version using Smart custom elements and template refs.

What this topic covers: practical setup, the framework-specific API access pattern, and copy-adapt guidance for the examples in this page.

<script setup>
import { onMounted, ref } from 'vue';
import 'smart-webcomponents/source/styles/smart.default.css';
import 'smart-webcomponents/source/modules/smart.grid.js';

const component = ref();
const componentProps = {
  // Copy this topic's JavaScript configuration here.
};

onMounted(() => {
  Object.assign(component.value, componentProps);
});
</script>

<template>
  <smart-grid ref="component"></smart-grid>
</template>

Use component.value for API methods in this topic.

Select Grid Rows Based on Certain Condition

Rows in Smart.Grid component can be selected initially based on certain condition. To be able to select multiple rows, selection.enabled and selection.allowRowSelection have to be set to true; moreover, selection.mode has to be set to 'many' or 'extended'.

The recommended way to manipulate rows initially, including their selection, is in the Grid's onRowInit callback function, which is called once for each row when it is initializing.

Here are three sample implementations of onRowInit showing how to select Grid rows based on different conditions:

Select Rows Depending on Index

The following code selects all rows with even indexes:

onRowInit(index: number, row: GridRow) {
    if (index % 2 === 0) {
        row.selected = true;
    }
}

Select All Rows Depending on Cell Value

The following code selects all rows whose Quantity cells have value greater than 5:

onRowInit(index: number, row: GridRow) {
    if (row.data.quantity > 5) {
        row.selected = true;
    }
}

Select All Rows Based on Complex Condition

onRowInit(index: number, row: GridRow) {
    if (index >= 10 && index <= 20 && (row.data.lastName === 'Fuller' || row.data.price > 20)) {
        row.selected = true;
    }
}
For AI tooling

Developer Quick Reference

Topic: grid-conditional-row-select   Component: Grid   Framework: Vue

Main methods: (none detected)

Common config keys: (none detected)

Implementation Notes

Compatibility: Vue 3+   API access pattern: const component = ref() + component.value.method()

Lifecycle guidance: Use template refs with