Skip to main content

GridView (그리드뷰) Widget Control

The Widget Control (Property · Method · Event) members you use to control the GridView widget from a script. For an introduction to the widget and how to use it, visit GridView.

info

The gridviewID in the examples below is the name (ID) you gave the GridView widget on the canvas. In scripts, access members as widgetID.member.

Widget Control summary

Widget ControlKindSignatureDescription
countPropertycount (read/write, integer)Read or set the number of repeated items
currentPropertycurrent (read/write, integer)Index of the current item used as the binding scope
selectPropertyselect (read/write, integer)Index of the selected item
addMethodadd() → integerAppend a new item and return its index
insertMethodinsert(index)Insert a new item at the given index
removeMethodremove(index)Remove the item at the given index
clearMethodclear()Remove every item
setStateMethodsetState(index, callback)Run a callback in one item's scope, then refresh only that item
scrollToIndexMethodscrollToIndex(index, duration)Scroll the given item into view, instantly or with an animation
getFirstVisibleIndexMethodgetFirstVisibleIndex() → integerReturn the index of the first visible item
onSelectedEventonSelected = (index) => { ... }Runs when the user taps an item

Property

count

Reads or sets the number of repeated items. Setting the value grows or shrinks the bound data list to match and redraws the grid.

  • Kind: Property (read/write)
  • Type / Returns: number (integer)

Example

gridviewID.count = 10;
const n = gridviewID.count;

current

Reads or sets the index of the item that currently acts as the binding scope. Once set, later property writes target that item's row. Reading returns -1 when no value is set.

  • Kind: Property (read/write)
  • Type / Returns: number (integer)

Example

gridviewID.current = 2;
const i = gridviewID.current;

select

Reads or sets the index of the selected item. Reading returns -1 when no item is selected.

  • Kind: Property (read/write)
  • Type / Returns: number (integer)

Example

gridviewID.select = 0;
const sel = gridviewID.select;

Method

add

Appends a new empty item and redraws the grid.

  • Parameters: None
  • Returns: number (integer) — the index of the newly added item

Example

const i = gridviewID.add();

insert

Inserts a new empty item at the given index and redraws the grid.

  • Parameters: index (number, integer) — where to insert the new item
  • Returns: None

Example

gridviewID.insert(0);

remove

Removes the item at the given index and redraws the grid. Nothing happens when the index is out of range.

  • Parameters: index (number, integer) — index of the item to remove
  • Returns: None

Example

gridviewID.remove(0);

clear

Removes every item and redraws the grid.

  • Parameters: None
  • Returns: None

Example

gridviewID.clear();

setState

Runs the callback with the binding scope set to the given item, then redraws only that item. Use it to refresh the bound properties of a single item.

  • Parameters: index (number, integer) — index of the item to refresh · callback (function) — callback to run in that item's scope
  • Returns: None

Example

gridviewID.setState(0, () => {
// Refresh the bound properties of the item at index 0
});

scrollToIndex

Scrolls the given item into view. The index is converted to a row and column position based on crossAxisCount. When duration is missing or 0 or lower, the grid jumps immediately; otherwise it animates for that many milliseconds. Nothing happens when the grid has not been laid out yet.

  • Parameters: index (number, integer) — index of the item to scroll to · duration (number | null, integer) — animation time in milliseconds; null or 0 jumps immediately
  • Returns: None

Example

gridviewID.scrollToIndex(20, 300);

getFirstVisibleIndex

Returns the item index of the first visible row and column. Returns 0 when the grid has not been laid out yet.

  • Parameters: None
  • Returns: number (integer) — index of the first visible item

Example

const index = gridviewID.getFirstVisibleIndex();

Event

onSelected

Runs when the user taps an item in the grid. The index of the tapped item is passed to the callback.

  • Kind: Event
  • Handler: a callback that receives an index (integer) argument
  • Returns: None

Example

gridviewID.onSelected = (index) => {
// The item at index is selected
};

Common Widget Control (all widgets)

note

Every widget can use name-based common Widget Control (Method) members such as setProperty / getProperty / setStyleProperty. See the common reference doc (to be written).