Skip to content

CGrid

Defines the Grid.

Vue Template Structure

vue
<template>
  <div class="demo-grid middle">
    <c-grid :data="records" :frozen-col-count="1">
      <!-- define checkbox -->
      <c-grid-check-column field="check" width="50" />
      <c-grid-column field="personid" width="85"> ID </c-grid-column>
      <!-- multiple header -->
      <c-grid-column-group caption="Name">
        <c-grid-input-column field="fname" width="20%" min-width="150">
          First Name
        </c-grid-input-column>
        <c-grid-input-column field="lname" width="20%" min-width="150">
          Last Name
        </c-grid-input-column>
      </c-grid-column-group>
      <!-- button -->
      <c-grid-button-column
        caption="SHOW REC"
        width="120"
        @click="onClickRecord"
      />
    </c-grid>
  </div>
</template>
<script>
export default {
  data() {
    return {
      records,
    };
  },
  methods: {
    onClickRecord(rec) {
      alert(JSON.stringify(rec));
    },
  },
};
</script>

Slots

default slot

Use this slot to set the simple header definition.
The definition is set to header property described in Define Headers and Columns

layout-header slot

Use this slot to set the layout header definition.
Use this slot in combination with the layout-body slot.
The definition is set to layout.header property described in Advanced Layout.

layout-body slot

Use this slot to set the layout body definition.
Use this slot in combination with the layout-header slot.
The definition is set to layout.body property described in Advanced Layout.

Properties

Optional Properties

NameTypeDescriptionDefault
dataArray|objectDefines a records or data source.undefined
frozen-col-countnumber|stringDefines a frozen col Count0
header-row-heightnumber|ArrayDefines the header row height(s)undefined
allow-range-pastebooleanAllow pasting of range.undefined
trim-on-pastebooleanTrim the pasted text on pasting.undefined
default-row-heightnumberDefault grid row height.undefined
default-col-widthnumberDefault grid col width.undefined
filterfunctionDefines a records filterundefined
fontstringDefault font.undefined
underlay-background-colorstringUnderlay background color.undefined
themeobject|stringDefines the grid themeundefined
move-cell-on-tab-keyboolean|functionSpecify true to enable cell movement by Tab key. You can also specify a function that determines which cell to move to.false
move-cell-on-enter-keyboolean|functionSpecify true to enable cell movement by Enter key. You can also specify a function that determines which cell to move to.false
delete-cell-value-on-del-keybooleanSpecify true to enable enable deletion of cell values with the Del and BS keys.undefined
select-all-on-ctrl-a-keybooleanSpecify true to enable select all cells by Ctrl + A key.undefined
disable-column-resizebooleanSpecify true to disable column resizingundefined
disabledbooleanDefines disabledundefined
readonlybooleanDefines readonlyundefined
optionsobjectDefines a raw options for Cheetah Gridundefined

Examples of using Properties

theme

vue
<template>
  <div class="demo-grid middle">
    <c-grid :data="records" :theme="userTheme">
      <!-- set theme -->
      <c-grid-check-column field="check" :width="50" />
      <c-grid-column field="personid" width="85">ID</c-grid-column>
      <c-grid-column-group caption="Name">
        <c-grid-input-column
          field="fname"
          width="20%"
          min-width="150"
          :sort="true"
          >First Name</c-grid-input-column
        >
        <c-grid-input-column
          field="lname"
          width="20%"
          min-width="150"
          :sort="true"
          >Last Name</c-grid-input-column
        >
      </c-grid-column-group>
      <c-grid-button-column
        caption="SHOW REC"
        width="120"
        @click="onClickRecord"
      />
    </c-grid>
  </div>
</template>
<script>
export default {
  name: "App",
  data() {
    return {
      records,
      // you can set the theme name or object.
      // userTheme: 'BASIC',
      userTheme: {
        color: "#2c3e50",
        frozenRowsColor: "#2c3e50",
        frozenRowsBgColor: "#40b883",
        borderColor: "#35495e",
        frozenRowsBorderColor: "#35495e",
        checkbox: {
          checkBgColor: "#35495e",
          borderColor: "#35495e",
        },
        button: {
          color: "#FFF",
          bgColor: "#2c3e50",
        },
      },
    };
  },
  methods: {
    onClickRecord(rec) {
      alert(JSON.stringify(rec));
    },
  },
};
</script>

Data

NameTypeInitial ValueDescription
headerValuesMap<any, any>new Map()Header values.

Events

NameDescription
click-cellClick on cell.
dblclick-cellDoubleclick on cell.
selected-cellSelected cell.
paste-cellPaste on cell.
changed-valueChanged value.
changed-header-valueChanged header value.

and more...

TIP

The events for which the column can be identified emit the same event to each column definition component.
e.g. <c-grid-column>

vue
<template>
  <div class="demo-grid middle">
    <c-grid :data="records" :frozen-col-count="1">
      <c-grid-column
        field="personid"
        width="85"
        @click-cell="onClickCell($event, 'ID')"
      >
        ID
      </c-grid-column>
      <c-grid-input-column
        field="fname"
        width="20%"
        @click-cell="onClickCell($event, 'First Name')"
      >
        First Name
      </c-grid-input-column>
      <c-grid-input-column
        field="lname"
        width="20%"
        @click-cell="onClickCell($event, 'Last Name')"
      >
        Last Name
      </c-grid-input-column>
    </c-grid>
  </div>
</template>
<script>
export default {
  data() {
    return {
      records,
    };
  },
  methods: {
    onClickCell(event, colName) {
      alert("Click at " + colName + ": $event=" + JSON.stringify(event));
    },
  },
};
</script>

Methods

NameReturn TypeDescription
invalidate---Redraws the whole grid.
updateSize---Apply the changed size.
updateScroll---Apply the changed scroll size.