When initializing the workbook, you can set an object configuration string ʻoptions` to customize the configuration of Luckysheet.
The following is a simple configuration example:
// Configuration item
const options = {
container:'luckysheet', // set the id of the DOM container
title:'Luckysheet Demo', // set the name of the table
lang:'zh' // set language
// More other settings...
}
// Initialize the table
luckysheet.create(options)
The options
configuration item here will affect the entire workbook. In particular, the configuration of a single worksheet needs to be set in the options.data
array to set corresponding more detailed parameters. Refer to Worksheet Configuration
For personalized needs, in addition to allowing configuration information bar (showinfobar), toolbar (showtoolbar), bottom sheet bar (showsheetbar), bottom count bar (ShowstatisticBar), Luckysheet has opened more detailed custom configuration options, which are as follows:
The following are all supported setting parameters
Usage: Configure the address of loadUrl
and use it in conjunction with loadSheetUrl
, which is generally used when the amount of data is large. You can also not use the interface parameters provided by Luckysheet, and use the data parameter to prepare all table data for initialization in advance.
Luckysheet will request the entire workbook data through ajax, and load all celldata
in the worksheet data with status 1 by default, and load all the fields except the celldata
field in the rest of the worksheets. However, considering that some formulas, charts and pivot tables will reference data from other worksheets, the front end will add a judgment. If the current worksheet references data from other worksheets, it will request data through the interface address configured by loadSheetUrl
, And load the data of the related worksheets. Because loadUrl
is only responsible for the current worksheet data, it is also necessary to configure loadSheetUrl
as an interface for asynchronously loading data.
loadSheetUrl
, the parameters are gridKey
(workbook primary key) and index
(worksheet primary key collection, the format is ["sheet_01","sheet_02","sheet_03"]
), the returned data is the celldata
field data collection of the worksheet. In order to load performance considerations, except for the first load of the celldata data of the current worksheet, the data of the other worksheets will be requested only when the worksheet is switched to that worksheet.updateUrl
allowUpdate
is true
. This interface is also the interface address for shared editing.Note that you also need to configure loadUrl
and loadSheetUrl
to take effect.
loadUrl
and loadSheetUrl
are not configured, you need to manually configure all the sheet data passed to the entire client [shee1, sheet2, sheet3]
. For detailed parameter settings, please refer to worksheet configurationshowtoolbar
, showtoolbarConfig
has a higher priority.Format:
{
undoRedo: false, //Undo redo
paintFormat: false, //Format brush
currencyFormat: false, //currency format
percentageFormat: false, //Percentage format
numberDecrease: false, //'Decrease the number of decimal places'
numberIncrease: false, //'Increase the number of decimal places
moreFormats: false, //'More Formats'
font: false, //'font'
fontSize: false, //'Font size'
bold: false, //'Bold (Ctrl+B)'
italic: false, //'Italic (Ctrl+I)'
strikethrough: false, //'Strikethrough (Alt+Shift+5)'
underline: false, // 'Underline (Alt+Shift+6)'
textColor: false, //'Text color'
fillColor: false, //'Cell color'
border: false, //'border'
mergeCell: false, //'Merge cells'
horizontalAlignMode: false, //'Horizontal alignment'
verticalAlignMode: false, //'Vertical alignment'
textWrapMode: false, //'Wrap mode'
textRotateMode: false, //'Text Rotation Mode'
image:false, // 'Insert picture'
link:false, // 'Insert link'
chart: false, //'chart' (the icon is hidden, but if the chart plugin is configured, you can still create a new chart by right click)
postil: false, //'comment'
pivotTable: false, //'PivotTable'
function: false, //'formula'
frozenMode: false, //'freeze mode'
sortAndFilter: false, //'Sort and filter'
conditionalFormat: false, //'Conditional Format'
dataVerification: false, // 'Data Verification'
splitColumn: false, //'Split column'
screenshot: false, //'screenshot'
findAndReplace: false, //'Find and Replace'
protection:false, // 'Worksheet protection'
print:false, // 'Print'
}
Example:
Show only the undo/redo
and font
buttons:
//options
{
showtoolbar: false,
showtoolbarConfig:{
undoRedo: true,
font: true,
}
}
Hide only the image
and print
buttons:
//options
{
showtoolbar: true, // The default is true, you can leave it unset
showtoolbarConfig:{
image: false,
print: false,
}
}
showsheetbar
, showsheetbarConfig
has a higher priority.Format:
{
add: false, //Add worksheet
menu: false, //Worksheet management menu
sheet: false //Worksheet display
}
Example:
Only display the Add worksheet
button:
//options
{
showsheetbar: false,
showsheetbarConfig:{
add: true,
}
}
Only hide the Add worksheet
and Worksheet management menu
buttons:
//options
{
showsheetbar: true, // The default is true, you can leave it unset
showsheetbarConfig:{
add: false,
menu: false,
}
}
showstatisticBar
, showstatisticBarConfig
has a higher priority.Format:
{
count: false, // Count bar
view: false, // Print view
zoom: false // Zoom
}
Example:
Only display the Zoom
button:
//options
{
showstatisticBar: false,
showstatisticBarConfig:{
zoom: true,
}
}
Only hide the print view
button:
//options
{
showstatisticBar: true, // The default is true, you can leave it unset
showstatisticBarConfig:{
view: false,
}
}
Type: Boolean
Default: true
Usage: Allow additional rows
Usage: User information display style in the upper right corner,Support the following three formats
HTML template string, such as:
options:{
// Other configuration
userInfo:'<i style="font-size:16px;color:#ff6a00;" class="fa fa-taxi" aria-hidden="true"></i> Lucky',
}
Or an ordinary string, such as:
options:{
// Other configuration
userInfo:'Lucky',
}
false
: Do not show
options:{
// Other configuration
userInfo:false, // Do not display user information
}
ture
: Show the default string
options:{
// Other configuration
userInfo:true, // Show HTML:'<i style="font-size:16px;color:#ff6a00;" class="fa fa-taxi" aria-hidden="true"></i> Lucky'
}
Object format, set userImage
: user avatar address and userName
: user name, such as:
options:{
// Other configuration
userImage:'https://cdn.jsdelivr.net/npm/luckyresources@1.0.3/assets/img/logo/logo.png', // Avatar url
userName:'Lucky', // username
}
Note that if set to undefined
or not set, the same as setting false
[{url:"www.baidu.com", "icon":'<i class="fa fa-folder" aria-hidden="true"></i>', "name":"我的表格"}, {url:"www.baidu.com", "icon":'<i class="fa fa-sign-out" aria-hidden="true"></i>', "name":"退出登陆"}]
<
back button in the upper left corner'<button id="" class="btn btn-primary" style="padding:3px 6px;font-size: 12px;margin-right: 10px;">download</button> <button id="" class="btn btn-primary btn-danger" style=" padding:3px 6px; font-size: 12px; margin-right: 10px;">share</button> <button id="luckysheet-share-btn-title" class="btn btn-primary btn-danger" style=" padding:3px 6px; font-size: 12px; margin-right: 10px;">show data</button>'
Usage: Force refresh formula.
By default, in order to improve loading performance, when the table is initialized, cells containing formulas will directly obtain v
and m
as data results by default without real-time calculation.
If the data of the cell associated with the formula has changed, or the result of the cell data where the formula is located has changed, it will cause the calculated result of the associated cell to be inconsistent with the actual displayed result. This requires the formula refresh to be turned on to ensure the data The accuracy of real-time calculations.
⚠️Reminder, there will be performance problems when there are more formulas, use it with caution!
Format:
{
copy: false, // copy
copyAs: false, // copy as
paste: false, // paste
insertRow: false, // insert row
insertColumn: false, // insert column
deleteRow: false, // delete the selected row
deleteColumn: false, // delete the selected column
deleteCell: false, // delete cell
hideRow: false, // hide the selected row and display the selected row
hideColumn: false, // hide the selected column and display the selected column
rowHeight: false, // row height
columnWidth: false, // column width
clear: false, // clear content
matrix: false, // matrix operation selection
sort: false, // sort selection
filter: false, // filter selection
chart: false, // chart generation
image: false, // insert picture
link: false, // insert link
data: false, // data verification
cellFormat: false // Set cell format
}
In addition to the cells, the configuration here also includes the row header right-click menu, the column header right-click menu, and the column header drop-down arrow menu. The specific configuration relationships are as follows:
Right-click menu configuration | Cell | Row header | Column header | Column arrow |
---|---|---|---|---|
copy | copy | copy | copy | copy |
copyAs | copy as | copy as | copy as | copy as |
paste | paste | paste | paste | paste |
insertRow | Insert a row | Increase N rows upwards and N rows downwards | - | - |
insertColumn | Insert Column | - | Add N columns to the left and N columns to the right | Add N columns to the left and N columns to the right |
deleteRow | Delete selected row | Delete selected row | - | - |
deleteColumn | Delete selected column | - | Delete selected column | Delete selected column |
deleteCell | Delete cell | - | - | - |
hideRow | - | Hide the selected row and show the selected row | - | - |
hideColumn | - | - | Hide the selected column and show the selected column | Hide the selected column and show the selected column |
rowHeight | - | row height | - | - |
columnWidth | - | - | Column Width | Column Width |
clear | clear content | clear content | clear content | - |
matrix | Matrix Operation Selection | Matrix Operation Selection | Matrix Operation Selection | - |
sort | Sort selection | Sort selection | Sort selection | A-Z sort and Z-A sort |
filter | Filter selection | Filter selection | Filter selection | - |
chart | chart generation | chart generation | chart generation | - |
image | Insert Picture | Insert Picture | Insert Picture | - |
link | Insert link | Insert link | Insert link | - |
data | Data Verification | Data Verification | Data Verification | - |
cellFormat | Set cell format | Set cell format | Set cell format | - |
Format:
{
delete: false, //Delete
copy: false, //Copy
rename: false, //Rename
color: false, //Change color
hide: false, //Hide, unhide
move: false, //Move to the left, move to the right
}
------------
### rowHeaderWidth
- Type: Number
- Default: 46
- Usage: The width of the row header area, if set to 0, it means to hide the row header
------------
### columnHeaderHeight
- Type: Number
- Default: 20
- Usage: The height of the column header area, if set to 0, it means hide the column header
------------
### sheetFormulaBar
- Type: Boolean
- Default: true
- Usage: Whether to show the formula bar
------------
### defaultFontSize
- Type:Number
- Default:11
- Usage:Initialize the default font size
------------
### limitSheetNameLength
- Type: Boolean
- Default: true
- Usage:Is the length of the sheet name limited in scenarios such as sheet renaming
------------
### defaultSheetNameMaxLength
- Type:Number
- Default:31
- Usage:Default maximum allowed sheet name length
------------
### pager
- Type:Object
- Default:null
- Usage:Pager button settings, the first version of the solution is directly used jquery plug-in [sPage](https://github.com/jvbei/sPage)
Clicking the paging button will trigger the hook function `onTogglePager`, which returns the current page number, which is the same as the `backFun` method of `sPage`. This pager setting is only responsible for the UI part. For the specific data request and data rendering after switching paging, please enter the `onTogglePager` custom processing in the number of hook lines.
js pager: {
pageIndex: 1, //Current page number
pageSize: 10, //How many rows of data are displayed on each page
total: 50, //Total number of rows of data
selectOption: [10, 20] //Options that allow setting the number of rows per page
}
------------
## Hook Function (TODO)
When the hook function is used in secondary development, hooks will be implanted in each common mouse or keyboard operation, and the function passed in by the developer will be called to expand the function of Luckysheet.
The hook functions are uniformly configured under ʻoptions.hook`, and configuration hooks can be created separately for cells, sheet pages, and tables.
## Cell
### cellEditBefore
- Type: Function
- Default: null
- Usage: Triggered before entering the cell editing mode. When a cell is selected and in the non-editing state, there are usually the following three conventional methods to trigger the edit mode
- Double click the cell
- Hit Enter
- Use API: enterEditMode
- Parameter:
- {Array} [range]: Current selection range
------------
### cellUpdateBefore
- Type: Function
- Default: null
- Usage: Triggered before updating this cell value, `return false` will not perform subsequent updates. After modifying the cell in the editing state, this hook is triggered before exiting the editing mode and updating the data.
- Parameter:
- {Number} [r]: The row number of the cell
- {Number} [c]: The column number of the cell
- {Object | String | Number} [value]: The content of the cell to be modified
- {Boolean} [isRefresh]: Whether to refresh the entire table
------------
### cellUpdated
- Type: Function
- Default: null
- Usage: Triggered after updating this cell
- Parameter:
- {Number} [r]: The row number of the cell
- {Number} [c]: The column number of the cell
- {Object} [oldValue]: Cell object before modification
- {Object} [newValue]: Modified cell object
- {Boolean} [isRefresh]: Whether to refresh the entire table
------------
### cellRenderBefore
- Type: Function
- Default: null
- Usage: Triggered before the cell is rendered, `return false` will not render the cell
- Parameter:
- {Object} [cell]:Cell object
- {Object} [position]:
+ {Number} [r]: The row number of the cell
+ {Number} [c]: The column number of the cell
+ {Number} [start_r]: The horizontal coordinate of the upper left corner of the cell
+ {Number} [start_c]: The vertical coordinate of the upper left corner of the cell
+ {Number} [end_r]: The horizontal coordinate of the lower right corner of the cell
+ {Number} [end_c]: The vertical coordinate of the lower right corner of the cell
- {Object} [sheet]: Current sheet object
- {Object} [ctx]: The context of the current canvas
------------
### cellRenderAfter
- Type: Function
- Default: null
- Usage: Triggered after the cell rendering ends, `return false` will not render the cell
- Parameter:
- {Object} [cell]: Cell object
- {Object} [position]:
+ {Number} [r]: The row number of the cell
+ {Number} [c]: The column number of the cell
+ {Number} [start_r]: The horizontal coordinate of the upper left corner of the cell
+ {Number} [start_c]: The vertical coordinate of the upper left corner of the cell
+ {Number} [end_r]: The horizontal coordinate of the lower right corner of the cell
+ {Number} [end_c]: The vertical coordinate of the lower right corner of the cell
- {Object} [sheet]: Current worksheet object
- {Object} [ctx]: The context of the current canvas
- Example:
A case of drawing two pictures in the upper left corner and lower right corner of cell D1
:::::: details
js luckysheet.create({
hook: {
cellRenderAfter: function (cell, position, sheetFile, ctx) {
var r = position.r;
var c = position.c;
if (r === 0 && c === 3) { // Specify to process cell D1
if (!window.storeUserImage) {
window.storeUserImage = {}
}
if (!window.storeUserImage[r + '_' + c]) {
window.storeUserImage[r + '_' + c] = {}
}
var img = null;
var imgRight = null;
if (window.storeUserImage[r + '_' + c].image && window.storeUserImage[r + '_' + c].imgRight) {
// Fetch directly after loading
img = window.storeUserImage[r + '_' + c].image;
imgRight = window.storeUserImage[r + '_' + c].imgRight;
} else {
img = new Image();
imgRight = new Image();
img.src = 'https://www.dogedoge.com/favicon/developer.mozilla.org.ico';
imgRight.src = 'https://www.dogedoge.com/static/icons/twemoji/svg/1f637.svg';
// The picture is cached in the memory, fetched directly next time, no need to reload
window.storeUserImage[r + '_' + c].image = img;
window.storeUserImage[r + '_' + c].imgRight = imgRight;
}
if (img.complete) { //Direct rendering that has been loaded
ctx.drawImage(img, position.start_c, position.start_r, 10, 10);
} else {
img.onload = function () {
ctx.drawImage(img, position.start_c, position.start_r, 10, 10);
}
}
if (imgRight.complete) {
ctx.drawImage(imgRight, position.end_c - 10, position.end_r - 10, 10, 10);
} else {
imgRight.onload = function () {
ctx.drawImage(imgRight, position.end_c - 10, position.end_r - 10, 10, 10);
}
}
}
}
}
})
``` :::
luckysheetDrawMain
renders the table.return false
will not render the row headerreturn false
will not render the row headerreturn false
will not render the column headerreturn false
will not render the column header(TODO)
(TODO)
(TODO)
index
of current worksheetOrder
of current worksheet(TODO)
index
of current worksheetorder
of the current worksheetorder
of the current worksheet(TODO)
(TODO)
(TODO)
index
of current worksheet(TODO)
index
of current worksheet(TODO)
index
of current worksheet(TODO)
index
of current worksheet(TODO)
index
of current worksheet(TODO)
index
of current worksheet(TODO)
index
of current worksheet(TODO)
index
of current worksheet(TODO)
index
of current worksheet(TODO)
index
of current worksheetbeforeCreateDom
{ r:0,c:2,v:{m:'233',v:'233'}}
{ r:0,c:2,v:{m:'233',v:'233'}}
, contains comment information
{ r:0,c:2,v:{m:'233',v:'233'}}
{ r:0,c:2,v:{m:'233',v:'233'}}
{ r:0,c:2,v:{m:'233',v:'233'}}
{ r:0,c:2,v:{m:'233',v:'233'}}
{ r:0,c:2,v:{m:'233',v:'233'}}
options.fireMousedown