实例方法
实例方法用于聚焦日期、跳转任务或读取渲染状态。它们只操作当前图表;任务数据、选中状态和服务端持久化仍由宿主控制。
跨端方法映射
| 目的 | Vue YgGanttExposed | React YgGanttReactHandle | Flutter YgGanttController |
|---|---|---|---|
| 按密度或最早任务聚焦 | focus(request?) | focus(request?) | 初始 autoFocus,或 fitToTasks() |
| 跳到日期 | scrollToDate(date, animate?) | scrollToDate(date, animate?) | scrollToDate(date, duration:) |
| 跳到任务 | scrollTaskIntoView(id, animate?) | scrollTaskIntoView(id, animate?) | scrollTaskIntoView(id, duration:) |
| 跳到行 | scrollToRow(index, animate?) | scrollToRow(index, animate?) | scrollToRow(index, duration:) |
| 适配数据范围 | fitToData(animate?) | fitToData(animate?) | fitToTasks() |
| 切换维度 | setView(view) | setView(view) | setView(viewMode) |
| 读取中心日期 | getAnchorDate() | getAnchorDate() | 当前版本未公开 |
| 选中任务 | selectTask(id) | selectTask(id) | 更新 selectedTaskId |
| 读取虚拟化统计 | getRenderStats() | getRenderStats() | 当前版本未公开 |
| 调整任务表列 | setTaskColumnWidth() / fitTaskColumns() | 当前版本未公开 | 当前版本未公开 |
Vue
vue
<script setup lang="ts">
import { ref } from 'vue'
import { YgGantt, type YgGanttExposed } from '@iyotsuba/gantt-vue'
const gantt = ref<YgGanttExposed | null>(null)
</script>
<template>
<button @click="gantt?.focus({ strategy: 'dense', scope: 'viewport' })">
定位密集区
</button>
<YgGantt ref="gantt" :tasks="tasks" />
</template>React
tsx
const gantt = useRef<YgGanttReactHandle>(null)
gantt.current?.scrollTaskIntoView('release')
gantt.current?.setView('month')
const stats = gantt.current?.getRenderStats()Flutter
dart
final controller = YgGanttController();
await controller.scrollToDate(DateTime.now());
await controller.scrollTaskIntoView('release');
await controller.scrollToRow(2400);
controller.setView(YgViewMode.month);
await controller.fitToTasks();Flutter 控制器在 Widget 挂载后才可用。可以先检查 controller.isAttached,页面销毁时由组件解除绑定。
