openharmony 鸿蒙 ohos-arkui-advanced-GridObjectSortComponent

2025-06-12 浏览 (1)

GridObjectSortComponent

GridObjectSortComponent is a grid object organizer that you can use to edit, drag to sort, add, and delete grid objects.

NOTE

This component is supported since API version 11. Updates will be marked with a superscript to indicate their earliest API version.

Modules to Import

import { GridObjectSortComponent, GridObjectSortComponentItem, GridObjectSortComponentOptions, GridObjectSortComponentType , SymbolGlyphModifier } from '@kit.ArkUI';

Child Components

Not supported

Attributes

The universal attributes are not supported.

GridObjectSortComponent

GridObjectSortComponent({options: GridObjectSortComponentOptions, dataList: Array<GridObjectSortComponentItem>, onSave: (select: Array<GridObjectSortComponentItem>, unselect: Array<GridObjectSortComponentItem>) => void, onCancel: () => void })

Decorator: @Component

Atomic service API: This API can be used in atomic services since API version 12.

System capability: SystemCapability.ArkUI.ArkUI.Full

NameTypeMandatoryDecoratorDescription
optionsGridObjectSortComponentOptionsYes@PropComponent configuration.
dataListArray<GridObjectSortComponentItem>Yes-Data to pass. The maximum data length is 50 characters. If it is exceeded, only the first 50 characters are used.
onSave(select: Array<GridObjectSortComponentItem>, unselect: Array<GridObjectSortComponentItem>) => voidYes-Callback invoked when changes are saved. The data after the changes is returned.
onCancel() => voidYes-Callback invoked when changes are canceled.

GridObjectSortComponentOptions

Atomic service API: This API can be used in atomic services since API version 12.

System capability: SystemCapability.ArkUI.ArkUI.Full

NameTypeMandatoryDescription
typeGridObjectSortComponentTypeNoComponent display form: text only or|text and imagery.
Default value: GridObjectSortComponentType.text
imageSizenumber |ResourceNoImage size, in vp.
The value must be greater than or equal to 0.
Default value: 56vp
normalTitleResourceStrNoTitle displayed in the non-editing state.
Default value: Channel
showAreaTitleResourceStrNoFirst subtitle of the display area.
Default value: Drag to sort
addAreaTitleResourceStrNoSecond subtitle of the display area.
Default value: Tap to add
editTitleResourceStrNoTitle displayed in the editing state.
Default value: Edit

GridObjectSortComponentType

Atomic service API: This API can be used in atomic services since API version 12.

System capability: SystemCapability.ArkUI.ArkUI.Full

NameValueDescription
IMAGE_TEXT'image_text'Text and imagery.
TEXT'text'Text only.

GridObjectSortComponentItem

System capability: SystemCapability.ArkUI.ArkUI.Full

NameTypeMandatoryDescription
idnumber |stringYesData ID, which must be unique.
The default value is an empty string.
Atomic service API: This API can be used in atomic services since API version 12.
textResourceStrYesText information.
Atomic service API: This API can be used in atomic services since API version 12.
selectedbooleanYesWhether the grid object has been added. The value true means that grid object has been added, and false means the opposite.
Atomic service API: This API can be used in atomic services since API version 12.
urlResourceStrNoURL of the image. Required when GridObjectSortComponentType is set to IMAGE_TEXT.
Atomic service API: This API can be used in atomic services since API version 12.
symbolStyle18+SymbolGlyphModifierNoSymbol resource of the image. Required when GridObjectSortComponentType is set to IMAGE_TEXT.
Atomic service API: This API can be used in atomic services since API version 18.
ordernumberYesSequence number.
The value must be greater than or equal to 0.
Default value: 0
Atomic service API: This API can be used in atomic services since API version 12.

Events

The universal events are not supported.

Example

This example illustrates the basic usage of the GridObjectSortComponent component, involving component configuration initialization, data initialization, and the use of the save and cancel APIs.

import { GridObjectSortComponent, GridObjectSortComponentItem, GridObjectSortComponentOptions, GridObjectSortComponentType, SymbolGlyphModifier } from '@kit.ArkUI';

@Entry
@Component
struct Index {
  // Initialize the component data.
  @State dataList: GridObjectSortComponentItem[] = [
    {
      id: 0,
      url: $r('sys.media.ohos_save_button_filled'),
      text: 'Download',
      selected: true,
      order: 3
    },
    {
      id: 1,
      url: $r('sys.media.ohos_ic_public_web'),
      text: 'Network',
      selected: true,
      order: 9
    },
    {
      id: 2,
      url: $r('sys.media.ohos_ic_public_video'),
      text: 'Video',
      selected: false,
      order: 1
    },
    {
      id: 3,
      symbolStyle: new SymbolGlyphModifier($r('sys.symbol.record_circle')),
      text: 'Recording',
      selected: false,
      order: 4
    }
  ]

  // Initialize the component configuration information.
  @State option: GridObjectSortComponentOptions = {
    type: GridObjectSortComponentType.IMAGE_TEXT,
    imageSize: 45,
    normalTitle: 'Menu',
    editTitle: 'Edit',
    showAreaTitle: 'Drag to sort',
    addAreaTitle: 'Touch to add'
  }

  build() {
    Column() {
      GridObjectSortComponent({
        options: this.option,
        dataList: this.dataList,
        // Callback invoked when changes are saved. The data after the changes is returned.
        onSave: (
          select: Array<GridObjectSortComponentItem>,
          unselect: Array<GridObjectSortComponentItem>
        ) => {
          // save ToDo
        },
        // Callback invoked when changes are canceled.
        onCancel: () =>{
          // cancel ToDo
        }
      })
    }
  }
}

GridObjectSortComponent

你可能感兴趣的鸿蒙文章

harmony 鸿蒙ArcButton

harmony 鸿蒙ArcSlider

harmony 鸿蒙Chip

harmony 鸿蒙ChipGroup

harmony 鸿蒙ComposeListItem

harmony 鸿蒙ComposeTitleBar

harmony 鸿蒙advanced.Counter

harmony 鸿蒙Dialog Box (Dialog)

harmony 鸿蒙DialogV2

harmony 鸿蒙DownloadFileButton

  • 所属分类: 后端技术
  • 本文标签: 软件 鸿蒙
  • 版权声明: 本文链接 https://seaxiang.com/blog/vVC3bP