1.2.7 • Published 3 years ago

oh-my-gantt v1.2.7

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

OH-MY-GANTT

English | 简体中文

Oh-my-gantt is a simple Gantt chart table tool that does not depend on third-party frameworks and can be integrated with major Javascript frameworks.

Installation

NPM

npm install oh-my-gantt -S
# or 
yarn add oh-my-gantt
// import to your js or ts
import 'oh-my-gantt/dist/index.css'
import { OhMyGantt } from 'oh-my-gantt'

Direct \<script> Include

<link rel="stylesheet"  href="https://unpkg.com/oh-my-gantt@1.2.7/dist/index.css" />
<script src="https://unpkg.com/oh-my-gantt@1.2.7/dist/index.umd.js"></script>
<script>
  var OhMyGantt = OMG.OhMyGantt
<script>

Usage

HTML

<div id="gantt-box"></div>

JavaScript

const data = [
  {
    name: 'Task 1',
    timebar: [
      {
        from: '2021-12-01',
        to: '2021-12-03',
        desc: 'Task 1',
      },
    ]
  },
  {
    name: 'Task 2',
    timebar: [
      {
        from: '2021-12-04',
        to: '2021-12-05',
        desc: 'Task 2',
        __config: { style: { backgroundColor: 'rgb(36, 112, 122)' } }
      },
    ]
  },
]

const gantt = new OhMyGantt('#gantt-box', {
  from: '2021-12-01',
  to: '2021-12-31',
  timeInterval: 'day',
  timeCellWidth: 120,
  columns: [
    {
      name: 'name',
      label: 'Task Name',
      width: 140,
    }
  ],
  data
})

OhMyGantt Instance

The OhMyGantt constructor wraps two parameters: element and Options

const myGanttInstacne = new OhMyGantt(element, {
  // ...Options
})

element

Provide the OhMyGantt instance an existing DOM element to mount on. It can be a CSS selector string or an actual HTMLElement.

Options

OptionDescriptTypeDefault value / ParamsReturn
fromSet the start time of the Gantt chart table displayDate | string
toSet the end time of the Gantt chart table displayDate | string
timeIntervalSet the time interval of the time column'day' |'hour' | 'week' | 'month' | 'year' | number'day'
dataGridWidthThe width setting of the data grid(the table on the left).number240
timeCellWidthThe width of each column of the time gridnumber120
timebarHeightheight of the timebarnumber32
timebarDraggableWhether the timebar allows draggingbooleanfalse
columnsData grid field settingsColumnItem[]
dataData content for displayMyGanttDataItem
timebarRendererA function for customizing the content rendered by the timebar(TimebarData, OhMyGantt)string or HTMLElement or null
timeGridCellRendererA function to customize the rendered content of timetable cells(data: ColumnItem, columnIndex: number, ctx: OhMyGantt)string or HTMLElement or null
timeLabelRendererThe function used to customize the rendered content of the sub-content of the header cell of the timetable header(data: ColumnItem, columnIndex: number, ctx: OhMyGantt)string or HTMLElement or null
onClickTimebarEvent fired when Timebar is clicked(TimebarData, Event)
onMouseoverTimebarEvent fired when the mouse passes the Timebar(TimebarData, Event)
onMouseleaveTimebarEvent fired when the mouse leaves the Timebar(TimebarData, Event)
onDragTimebarEvent fired when timebar is dragged(TimebarData, Event)
onDragstartTimebarEvent fired when the timebar starts to be dragged(TimebarData, Event)
onDragendTimebarEvent fired when the timebar is finished dragging(TimebarData, Event)
onClickCellEvent fired when cell is clicked( CellData, Event)
onDropCellThe event fired when the timebar is dragged and dropped to the cell(CellData, Event)
onDragoverCellThe event fired when the timebar is drag over the cell(CellData, Event)
onDragenterCellThe event triggered when the timebar is dragged enter the cell(CellData, Event)
onDragleaveCellEvent fired when timebar is dragged away from cell(CellData, Event)
onScrollEvent fired when table scrolls(GridScrollData, Event)
onCreatedEvent fired after the line executes new OhMyGantt(Element, Options)(OhMyGantt)
onRenderedEvent fired after rendering the table(OhMyGantt)

Methods and Props

Prop/MethodDescriptTypeReturn
elementThe target Dom that was mounted when the instance was createdElement
dataThe data set when the instance was createdMyGanttDataItem[]
timeListTime list of all time in the time gridDate[]
fromStart time of the time gridDate
toEnd time of the time gridDate
optionsSetting items when creating an instanceOptions
$elementsThe object of the HTMLElement object that stores the data table and the time table after the instance is created{ dataGrid: HTMLElement | null, timeGrid: HTMLElement | null }
renderDataGridMethod: Render the left table (Data grid()=>HTMLElement, number
Returns the HTMLElement of the data grid and its width
renderTimeGridMethod: Render the right table (Time grid)()=>HTMLElement, number
Returns the HTMLElement of the time grid and its width
renderMethod: Render the table (the renderDataGrid and renderTimeGrid methods will be executed)()=>void
getScrollTopMethod: Get the scroll top of the table() => numberReturn scroll top
getRowDataByIndexGet the data of the row by the index value of the row(index: number) => MyGanttDataItem | nullreturn the row of data
getRowDataByIdGet the row data by row id(index: number) => MyGanttDataItem | nullreturn the row of data
setMarkLineSet a mark line(markLine: MarkLine)=> void
removeMarkLineremove a mark line(markLine: MarkLine)=> void
scrollToTimeThe time grid scrolls horizontally to the specified time(time: Datestring)=> void
setScrollTopScroll the table to the specified height(top: number)=> void
scrollToRowScrolls the table to the specified row by row id or index value({index: number})=> void | ({id: string | number })=> void

Type and interface

MyGanttDataItem

PropsDescriptTypeRequired
timebartimebar设置TimebarSetting[]
__configThe related settings for this row{ height?: number, key: string: any}
key: string数据表格有其它任意数据any

TimebarSetting

PropsDescriptTypeRequired
fromStart time of timebarDate | stringYes
toEnd time of timebarDate | stringYes
__configThe relevant settings of the timebar{ style?: number, key: string: any}

ColumnItem

PropsDescriptTypeRequired
namecolumn namestringYes
labelThis column displays the content of the headerstringYes
widthset column widthnumber
sourceDataCustomized data content (if it is in the time table, it will be automatically generated, and its value is the timestamp of the time in this column)any

CellData

PropsDescriptType
rowDataData of the current rowany
$targetThe HTMLElement for the current cellHTMLElement
rowIndexThe index value of the current rownumber
valueThe value of the current cellany
columnIndexThe index value of the current columnnumber
columnNameThe name of the current columnany

TimebarData

PropsDescriptType
rowDataData of the current rowany
$targetThe HTMLElement for the current timebarHTMLElement
rowIndexThe index value of the row where the current timebar is locatednumber
valueThe value of the current timebar starting cell (usually the timestamp of the column time)string
columnIndexThe index value of the current timebar starting cellany
timeColumnsIndexThe index of the field occupied by the current timebarany
timebarItemDataCurrent timebar related settingsTimebarSetting

MarkLine instance

import { MarkLine } from 'oh-my-gantt'

const markLineInstance = new MarkLine({
  // ...MarkLine Options
})

// add a markLine
myGanttInstacne.setMarkLine(markLineInstance)

// remove markLine
myGanttInstacne.removeMarkLine(markLineInstance)

MarkLine Options

OptionDescriptTypeDefaultRequired
timeThe time corresponding to the time griddate | stringYes
labelThe text content displayed by the marker line labelstringYes
colorThe color of the mark linestring'#0086d4'
lineStyleLine style'solid' | 'dashed' | 'dotted''solid'
lineWidthLine widthnumber1

The props of the MarkLine instance

PropsDescriptType
optionsSetting items when creating MarkLineMarkLineOptions
idUnique ID generated when MarkLine is createdstring
$elementHTMLElement generated when MarkLine is createdHTMLElement
1.2.7

3 years ago

1.2.6

3 years ago

1.2.5

3 years ago

1.2.4

3 years ago

1.2.3

3 years ago

1.2.2

3 years ago

1.2.1

3 years ago

1.2.0

3 years ago

1.1.0

3 years ago

1.0.0

3 years ago

0.2.0

3 years ago

0.1.1

3 years ago

0.1.0

3 years ago