Class: TableEditorView

TableEditorView()

A view of an HTML textarea with markdown editor UI and preview tab

Constructor

new TableEditorView()

Source:

Extends

  • Backbone.View

Members

className :string

The HTML classes to use for this view's element
Type:
  • string
Source:

colCount :number

The current number of columns displayed in the spreadsheet, including the row number column
Type:
  • number
Source:

defaults :object

Default row & column count for empty tables
Type:
  • object
Source:

events :Object

The events this view will listen to and the associated function to call.
Type:
  • Object
Source:

rowCount :number

The current number of rows displayed in the spreadsheet, including the header row
Type:
  • number
Source:

sortingHistory :map

Map for storing the sorting history of every column
Type:
  • map
Source:

tableData :string

The same data shown in the table as a stringified JSON object.
Type:
  • string
Source:

template :Underscore.Template

References to templates for this view. HTML files are converted to Underscore.js templates
Type:
  • Underscore.Template
Source:

type :string

The type of View this is
Type:
  • string
Source:

Methods

addColumn(currentCol, direction)

addColumn - Utility function to add columns
Parameters:
Name Type Description
currentCol number The column number at which to add a new column
direction string Can be "left" or "right", indicating whether to new column should be to the left or right of the current column
Source:

addRow(currentRow, direction)

addRow - Utility function to add row
Parameters:
Name Type Description
currentRow number The row number at which to add a new row
direction string Can be "top" or "bottom", indicating whether to new row should be above or below the current row
Source:

ascSort(currentCol, a, b) → {number}

ascSort - Compare Functions for sorting - ascending
Parameters:
Name Type Description
currentCol number The number of the column to sort
a * One of two items to compare
b * The second of two items to compare
Source:
Returns:
A number indicating the order to place a vs b in the list. It it returns less than zero, then a will be placed before b in the list.
Type
number

closeDropdown(e)

closeDropdown - Close the dropdown menu if the user clicks outside of it
Parameters:
Name Type Description
e type The event that triggered this function
Source:

createHeaderRow()

createHeaderRow - Create a header row for the table
Source:

createSpreadsheet()

createSpreadsheet - Creates or re-creates the table & headers with data, if there is any.
Source:

createTableBody(tableBody)

createTableBody - Given a table element, add table rows
Parameters:
Name Type Description
tableBody HTMLElement A table HTML Element
Source:

createTableBodyRow(rowNum)

createTableBodyRow - Create a row for the table
Parameters:
Name Type Description
rowNum number The table row number to add to the table, where 0 is the header row
Source:

deleteColumn(currentCol)

deleteColumn - Utility function to delete column
Parameters:
Name Type Description
currentCol number The number of the column to delete
Source:

deleteRow(currentRow)

deleteRow - Utility function to delete row
Parameters:
Name Type Description
currentRow number The row number to delete
Source:

dscSort(currentCol, a, b) → {number}

dscSort - Descending compare function
Parameters:
Name Type Description
currentCol number The number of the column to sort
a * One of two items to compare
b * The second of two items to compare
Source:
Returns:
A number indicating the order to place a vs b in the list. It it returns less than zero, then a will be placed before b in the list.
Type
number

getData()

getData - Get the saved data and parse it. If there's no saved data, create it.
Source:

getJSONfromMarkdown(markdown) → {Array}

getJSONfromMarkdown - Converts a given markdown table string to JSON.
Parameters:
Name Type Description
markdown string description
Source:
Returns:
The markdown table as an array of arrays, where the header is the first array and each row is an array that follows.
Type
Array

getMarkdown() → {string}

convertToMarkdown - Returns the table data as markdown
Source:
Returns:
The markdownified table as string
Type
string

handleBodyClick(e) → {type}

handleHeadersClick - Called when the table body is clicked. Depending on what is clicked, shows or hides the dropdown menus in the body, or calls one of the functions listed in the menu (e.g. delete row).
Parameters:
Name Type Description
e type description
Source:
Returns:
description
Type
type

handleHeadersClick(e)

handleHeadersClick - Called when the table header is clicked. Depending on what is clicked, shows or hides the dropdown menus in the header, or calls one of the functions listed in the menu (e.g. delete column).
Parameters:
Name Type Description
e event The event that triggered this function
Source:

hasEmptyCol1(data) → {boolean}

hasEmptyCol1 - Checks whether the first column is empty.
Parameters:
Name Type Description
data Object The table data in the form of an array of arrays
Source:
Returns:
returns true if the first column is empty, false if at least one cell in the first column contains a value
Type
boolean

initializeData()

initializeData - Create some empty arrays to hold data
Source:

populateTable()

populateTable - Fill data in created table from saved data
Source:

render()

render - Renders the tableEditor - add UI for creating and editing tables
Source:

resetData(e)

resetData - Clear the saved data and reset the table to the default number of rows & columns
Parameters:
Name Type Description
e event the event that triggered this function
Source:

saveData(data) → {type}

saveData - Save the data as a string.
Parameters:
Name Type Description
data type description
Source:
Returns:
description
Type
type

sortColumn(currentCol)

sortColumn - Utility function to sort columns
Parameters:
Name Type Description
currentCol number The column number of the column to delete
Source:

updateData(e)

updateData - When the user focuses out, presume they've changed the data, and updated the saved data.
Parameters:
Name Type Description
e event The focus out event that triggered this function
Source:

TableEditorView(options)

new TableEditorView(options)

Initialize is executed when a new tableEditor is created.
Parameters:
Name Type Description
options Object A literal object with options to pass to the view
Source:

Members

className :string

The HTML classes to use for this view's element
Type:
  • string
Source:

colCount :number

The current number of columns displayed in the spreadsheet, including the row number column
Type:
  • number
Source:

defaults :object

Default row & column count for empty tables
Type:
  • object
Source:

events :Object

The events this view will listen to and the associated function to call.
Type:
  • Object
Source:

rowCount :number

The current number of rows displayed in the spreadsheet, including the header row
Type:
  • number
Source:

sortingHistory :map

Map for storing the sorting history of every column
Type:
  • map
Source:

tableData :string

The same data shown in the table as a stringified JSON object.
Type:
  • string
Source:

template :Underscore.Template

References to templates for this view. HTML files are converted to Underscore.js templates
Type:
  • Underscore.Template
Source:

type :string

The type of View this is
Type:
  • string
Source:

Methods

addColumn(currentCol, direction)

addColumn - Utility function to add columns
Parameters:
Name Type Description
currentCol number The column number at which to add a new column
direction string Can be "left" or "right", indicating whether to new column should be to the left or right of the current column
Source:

addRow(currentRow, direction)

addRow - Utility function to add row
Parameters:
Name Type Description
currentRow number The row number at which to add a new row
direction string Can be "top" or "bottom", indicating whether to new row should be above or below the current row
Source:

ascSort(currentCol, a, b) → {number}

ascSort - Compare Functions for sorting - ascending
Parameters:
Name Type Description
currentCol number The number of the column to sort
a * One of two items to compare
b * The second of two items to compare
Source:
Returns:
A number indicating the order to place a vs b in the list. It it returns less than zero, then a will be placed before b in the list.
Type
number

closeDropdown(e)

closeDropdown - Close the dropdown menu if the user clicks outside of it
Parameters:
Name Type Description
e type The event that triggered this function
Source:

createHeaderRow()

createHeaderRow - Create a header row for the table
Source:

createSpreadsheet()

createSpreadsheet - Creates or re-creates the table & headers with data, if there is any.
Source:

createTableBody(tableBody)

createTableBody - Given a table element, add table rows
Parameters:
Name Type Description
tableBody HTMLElement A table HTML Element
Source:

createTableBodyRow(rowNum)

createTableBodyRow - Create a row for the table
Parameters:
Name Type Description
rowNum number The table row number to add to the table, where 0 is the header row
Source:

deleteColumn(currentCol)

deleteColumn - Utility function to delete column
Parameters:
Name Type Description
currentCol number The number of the column to delete
Source:

deleteRow(currentRow)

deleteRow - Utility function to delete row
Parameters:
Name Type Description
currentRow number The row number to delete
Source:

dscSort(currentCol, a, b) → {number}

dscSort - Descending compare function
Parameters:
Name Type Description
currentCol number The number of the column to sort
a * One of two items to compare
b * The second of two items to compare
Source:
Returns:
A number indicating the order to place a vs b in the list. It it returns less than zero, then a will be placed before b in the list.
Type
number

getData()

getData - Get the saved data and parse it. If there's no saved data, create it.
Source:

getJSONfromMarkdown(markdown) → {Array}

getJSONfromMarkdown - Converts a given markdown table string to JSON.
Parameters:
Name Type Description
markdown string description
Source:
Returns:
The markdown table as an array of arrays, where the header is the first array and each row is an array that follows.
Type
Array

getMarkdown() → {string}

convertToMarkdown - Returns the table data as markdown
Source:
Returns:
The markdownified table as string
Type
string

handleBodyClick(e) → {type}

handleHeadersClick - Called when the table body is clicked. Depending on what is clicked, shows or hides the dropdown menus in the body, or calls one of the functions listed in the menu (e.g. delete row).
Parameters:
Name Type Description
e type description
Source:
Returns:
description
Type
type

handleHeadersClick(e)

handleHeadersClick - Called when the table header is clicked. Depending on what is clicked, shows or hides the dropdown menus in the header, or calls one of the functions listed in the menu (e.g. delete column).
Parameters:
Name Type Description
e event The event that triggered this function
Source:

hasEmptyCol1(data) → {boolean}

hasEmptyCol1 - Checks whether the first column is empty.
Parameters:
Name Type Description
data Object The table data in the form of an array of arrays
Source:
Returns:
returns true if the first column is empty, false if at least one cell in the first column contains a value
Type
boolean

initializeData()

initializeData - Create some empty arrays to hold data
Source:

populateTable()

populateTable - Fill data in created table from saved data
Source:

render()

render - Renders the tableEditor - add UI for creating and editing tables
Source:

resetData(e)

resetData - Clear the saved data and reset the table to the default number of rows & columns
Parameters:
Name Type Description
e event the event that triggered this function
Source:

saveData(data) → {type}

saveData - Save the data as a string.
Parameters:
Name Type Description
data type description
Source:
Returns:
description
Type
type

sortColumn(currentCol)

sortColumn - Utility function to sort columns
Parameters:
Name Type Description
currentCol number The column number of the column to delete
Source:

updateData(e)

updateData - When the user focuses out, presume they've changed the data, and updated the saved data.
Parameters:
Name Type Description
e event The focus out event that triggered this function
Source: