# Cell merge Cell merging refers to merging multiple cells into one cell, which is commonly used for functions such as merging and displaying duplicate content. ## Automatic cell merge In VTable, you can configure `mergeCell` on a column to merge adjacent cells with the same content in the same column. ### Example ```javascript livedemo template=vtable let tableInstance; fetch('https://lf9-dp-fe-cms-tos.byteorg.com/obj/bit-cloud/VTable/North_American_Superstore_data100.json') .then((res) => res.json()) .then((data) => { const columns =[ { "field": "Category", "title": "Category", "width": "auto", sort:true, "mergeCell": true, style:{ "textStick":true, textAlign:'right' // textBaseline:"bottom" } }, { "field": "Sub-Category", "title": "Sub-Category", "width": "auto", sort:true, "mergeCell": true, }, { "field": "Order ID", "title": "Order ID", "width": "auto" }, { "field": "Customer ID", "title": "Customer ID", "width": "auto" }, { "field": "Product Name", "title": "Product Name", "width": "auto", headerStyle:{ "textStick":true, } }, { "field": "Region", "title": "Region", "width": "auto" }, { "field": "City", "title": "City", "width": "auto" }, { "field": "Order Date", "title": "Order Date", "width": "auto" }, { "field": "Quantity", "title": "Quantity", "width": "auto" }, { "field": "Sales", "title": "Sales", "width": "auto" }, { "field": "Profit", "title": "Profit", "width": "auto" } ]; const option = { records:data, columns, widthMode:'standard', hover:{ highlightMode:'row' }, sortState:{ field:'Category', order:'asc' } }; tableInstance = new VTable.ListTable(document.getElementById(CONTAINER_ID),option); window['tableInstance'] = tableInstance; }) ``` If `mergeCell` is configured, adjacent cells with the same content in the same column will be merged and displayed. ## Custom cell merge In VTable, you can configure `customMergeCell` to customize the merging method of cells. This method is often used to display some label information. The `customMergeCell` callback function will pass in the column number and table instance, determine the cells that need to be merged in the function, and return the corresponding merging rules: * text: Merge text in cells * range: merged range * style: style of merged cells `customMergeCell` can also be configured as an array of merge rules. Each item in the array is a merge rule. The configuration of the rule is the same as the return value of the `customMergeCell` callback function. ### Example ```javascript livedemo template=vtable let tableInstance; const generatePersons = count => { return Array.from(new Array(count)).map((_, i) => ({ id: i + 1, email1: `${i + 1}@xxx.com`, name: `name${i + 1}`, date1: '2022-9-1日', tel: '000-0000-0000', sex: i % 2 === 0 ? 'boy' : 'girl', work: i % 2 === 0 ? 'back-end engineer' : 'front-end engineer', city: 'beijing' })); }; const records = generatePersons(10); const columns = [ { field: 'id', title: 'ID ff', width: '1%', minWidth: 200, sort: true }, { field: 'email1', title: 'email', width: 200, sort: true }, { title: 'full name', columns: [ { field: 'name', title: 'First Name', width: 200 }, { field: 'name', title: 'Last Name', width: 200 } ] }, { field: 'date1', title: 'birthday', width: 200 }, { field: 'sex', title: 'sex', width: 100 }, { field: 'tel', title: 'telephone', width: 150 }, { field: 'work', title: 'job', width: 200 }, { field: 'city', title: 'city', width: 150 } ]; const option = { records, columns, widthMode:'standard', customMergeCell: (col, row, table) => { if (col > 0 && col < 8 && row > 7 && row < 11) { return { text: 'long long long long long long long long long long long long long long long long long long text!', range: { start: { col: 1, row: 8 }, end: { col: 7, row: 10 } }, style: { bgColor: '#ccc' } }; } } }; tableInstance = new VTable.ListTable(document.getElementById(CONTAINER_ID),option); window['tableInstance'] = tableInstance; ```