Working with GridJs Client Side

Working with GridJs Client Side

We developed GridJs client based on x-spreadsheet.

the main steps are:

  • create x_spreadsheet instance
xs = x_spreadsheet(id, options)
    // the parameters are:
    id:the html node id ,for example :'#gridjs-demo' for the html  <div id="gridjs-demo"></div>
    options:the load options,
     // the parameters for options:
	    updateMode:  currently we only support 'server'
	    updateUrl:  set the server side  url for update action based on json
	    mode: read means readonly spread sheet/edit means we can edit the spread sheet
	    showToolbar:   means whether to show toolbar
	    showFileName:  whether to show the filename 
	    local:         support multiple language for menus ,the locale can be:
	                        en, cn, es, pt, de, ru, nl, 
	                   for  English,Chinese,Spanish,Portuguese,German,Russian,Dutch
			        ar, fr,id,it,ja
                           for  Arabic,French,Indonesian,Italian,Japanese
			        ko,th,tr,vi,cht
                           for  Korean,Thai,Turkey,Vietnamese,Traditional Chinese                  
	    showContextmenu:   means whether to show contextmenu on right click on a cell

	for example the below code init a x_spreadsheet object.
	xs = x_spreadsheet('#gridjs-demo', {
			updateMode:'server',
			updateUrl:'/GridJs2/UpdateCell',
			mode: 'edit',
			showToolbar: true,
                        local: 'en',
			showContextmenu: true
			})
  • load with json data
xs.loadData(data)
// the parameters is:
	data: the json data which describ the data structure for the worksheets
  • set active sheet by sheetname
xs.setActiveSheetByName(sheetname)
// the parameters is:
	sheetname: the sheet name 
  • set active sheet by id
xs.setActiveSheet(id)
// the parameters is:
	sheetname: the sheet id 
  • set active cell
xs.setActiveCell(row,col);
// the parameters are:
	row: the cell row
	col: the cell column

other useful apis

  • Render the view
xs.reRender()
  • get active sheet id
xs.getActiveSheet()
  • Set Zoom level
xs.setZoomLevel(zoom)
// the parameters is:
	zoom:the zoom level ,can be number ,for example 0.5 for zoom out, or 2 for zoom in
  • Set FileName
xs.setFileName(name)
// the parameters is:
	name:the file name with extension ,for example trip.xlsx
  • set visible filter for image/shape
    // need to set a function which return true(for visible) or false(for invisible) for the visible filter with the below parameters :
	sheet:the sheet instance
	s:the image or shape instance
    for example: 
	//this will make visible for image/shape in sheet with name 'Sheet3' and 'Sheet1' except for the 'Rectangle' type
		xs.setVisibleFilter((sheet,s) => { if (sheet.data.name==='Sheet3'||sheet.data.name==='Sheet1') return s.type!=='Rectangle';  return false; })
	//this will make visible for image/shape in sheet with name  'Sheet1' 
		xs.setVisibleFilter((sheet,s) => { if (sheet.data.name==='Sheet1') return true;  return false; })
	//this will make invisible for image/shape in all sheets 
		xs.setVisibleFilter((sheet,s) => {  return false; })
	//if all the image/shape is already loaded and you want to change the visible filter at runtime,you can call the below code to trigger a reload for image/shape
		xs.setActiveSheet(xs.getActiveSheet())
  • Get the selected image/shape,if nothing select will return null
xs.sheet.selector.getObj()
  • Get the cell object
xs.sheet.data.getCell(ri,ci)
    // the parameters are:
	ri:row index 
	ci:column index
  • Get the cell style
xs.sheet.data.getCellStyle(ri,ci)
    // the parameters are:
	ri:row index 
	ci:column index
  • Set the cell value
xs.sheet.data.setCellText(ri,ci,value,state)
    // the parameters are:
	ri:row index 
	ci:column index
	value:the cell value
	state: input | finished
  • Get/Set the selected cell range
xs.sheet.data.selector.range
  • Set the cell value for the selected cell or cell area
xs.sheet.data.setSelectedCellText(value)
    // the parameters are:
	value:the  value for the cell
  • Set the style for the selected cell or cell area
xs.sheet.data.setSelectedCellAttr(attributename,value)
    // the parameters are:
	attributename:font-name | font-bold | font-italic | font-size  | format|border|merge|formula |strike|textwrap |underline |align |valign |color|bgcolor|pattern
	value:the  value for the attribute
  • Merge the selected cell area
xs.sheet.data.merge()
  • Unmerge the selected cell area
xs.sheet.data.unmerge()
  • Delete the selected cell
xs.sheet.data.deleteCell(type)
    // the parameters are:
	type:all|format  all: means delete the cell and clear the style ;format means delete the cell value and keep the cell style
  • Set the freeze pane
xs.sheet.data.setFreeze(ri,ci)
    // the parameters are:
	ri:row index 
	ci:column index
  • Insert row or columns at the selected cell
xs.sheet.data.insert(type, n)
    // the parameters are:
	type: row | column
	n:the row or column number
  • Delete row or columns at the selected cell
xs.sheet.data.delete(type)
    // the parameters are:
	type: row | column
  • Set the width for the column
xs.sheet.data.setColWidth(ci,width)
    // the parameters are:
	ci:column index
	width:the width for the column
  • Get the width for the column
xs.sheet.data.cols.sumWidth(min,max)
    // the parameters are:
	min:the start column index
	max:the end column index,not include
  • Set the height for the row
xs.sheet.data.setRowHeight(ri,height)
    // the parameters are:
	ri:row index
	height:the height for the row
  • Get the height for the row
xs.sheet.data.rows.sumHeight(min,max)
    // the parameters are:
	min:the start row index
	max:the end row index,not include
  • Get/Set the display direction
xs.sheet.data.displayRight2Left

customization

  • set home icon and link
xs.sheet.menubar.icon.setHomeIcon(iconUrl,targetUrl)
    // the parameters are:
	iconUrl:the home icon URL
	targetUrl:the target link URL
	for example ,the below code will set the new logo and with link to google.com
	xs.sheet.menubar.icon.setHomeIcon('https://forum.aspose.com/letter_avatar_proxy/v4/letter/y/3e96dc/45.png','https://www.google.com')
  • show the menu bar
xs.sheet.menubar.show()
  • hide the menu bar
xs.sheet.menubar.hide()

for detail info ,you can check the example here https://github.com/aspose-cells/Aspose.Cells-for-.NET/tree/master/Examples_GridJs