JSDoc: Class: Sorting

# Class: Sorting

## FooTable.Sorting

#### new Sorting(table) → {FooTable.Sorting}

The sorting component adds a small sort button to specified column headers allowing users to sort those columns in the table.

##### Parameters:

Name | Type | Description
--- | --- | ---
`table` | FooTable.Table | The parent `FooTable.Table` object for the component.

##### Returns:

Type
  FooTable.Sorting

### Extends

- FooTable.Component

### Members

#### allowed :boolean

Whether or not to allow sorting to occur, should be set using the `FooTable.Sorting#toggleAllowed` method.

##### Type:

- boolean

#### column :FooTable.Column

The current sorted column.

##### Type:

- FooTable.Column

#### enabled :boolean

Whether or not this component is enabled. Disabled components only have there preinit method called allowing for this value to be overridden.

##### Type:

- boolean

Inherited From:
  - FooTable.Component#enabled

#### ft :FooTable.Table

The parent `FooTable.Table` for the component.

##### Type:

- FooTable.Table

Inherited From:
  - FooTable.Component#ft

#### initial :Object

The initial sort state of the table, this value is used for determining if the sorting has occurred or to reset the state to default.

##### Type:

- Object

#### (protected) o :object

This provides a shortcut to the `FooTable.Table#options`.`sorting` object.

##### Type:

- object

### Methods

#### (static) hasChanged() → {boolean}

Checks whether any sorting has occurred for the table.

##### Returns:

Type
  boolean

#### (static) reset()

Resets the table sorting to the initial state recorded in the components init method.

#### (static) toggleAllowed(stateopt)

Toggles whether or not sorting is currently allowed.

##### Parameters:

Name | Type | Attributes | Description
--- | --- | --- | ---
`state` | boolean | <optional> | You can optionally specify the state you want it to be, if not supplied the current value is flipped.

#### (private) _onSortClicked(e)

Handles the sort button clicked event.

##### Parameters:

Name | Type | Description
--- | --- | ---
`e` | jQuery.Event | The event object for the event.

#### (private) _sort(column, directionopt) → {jQuery.Promise}

Performs the required steps to handle sorting including the raising of the `FooTable.Sorting#"before.ft.sorting"` and `FooTable.Sorting#"after.ft.sorting"` events.

##### Parameters:

Name | Type | Attributes | Default | Description
--- | --- | --- | --- | ---
`column` | string | number | FooTable.Column |  |  | The column name, index or the actual `FooTable.Column` object to sort by.
`direction` | string | <optional> | "ASC" | The direction to sort by, either ASC or DESC.

##### Fires:

- FooTable.event:Sorting"before.ft.sorting"
- FooTable.event:Sorting"after.ft.sorting"

##### Returns:

Type
  jQuery.Promise

#### (protected) destroy()

Destroys the sorting component removing any UI generated from the table.

Overrides:
  - FooTable.Component#destroy

##### Fires:

- FooTable.event:Sorting"destroy.ft.sorting"

#### (protected) draw()

Updates the sorting UI setting the state of the sort buttons.

Overrides:
  - FooTable.Component#draw

#### (protected) init()

Initializes the sorting component for the plugin using the supplied table and options.

##### This:

- FooTable.Sorting

Overrides:
  - FooTable.Component#init

##### Fires:

- FooTable.event:Sorting"init.ft.sorting"

#### (protected) postdraw()

This method is called from the `FooTable.Table#draw` method.

Inherited From:
  - FooTable.Component#postdraw

#### (protected) predraw()

Performs the actual sorting against the `FooTable.Rows#current` array.

Overrides:
  - FooTable.Component#predraw

#### (protected) preinit(data)

Checks the supplied data and options for the sorting component.

##### This:

- FooTable.Sorting

##### Parameters:

Name | Type | Description
--- | --- | ---
`data` | object | The jQuery data object from the parent table.

Overrides:
  - FooTable.Component#preinit

##### Fires:

- FooTable.event:Sorting"preinit.ft.sorting"

#### sort(column, directionopt) → {jQuery.Promise}

Sets the sorting options and calls the `FooTable.Table#draw` method to perform the actual sorting.

##### Parameters:

Name | Type | Attributes | Default | Description
--- | --- | --- | --- | ---
`column` | string | number | FooTable.Column |  |  | The column name, index or the actual `FooTable.Column` object to sort by.
`direction` | string | <optional> | "ASC" | The direction to sort by, either ASC or DESC.

##### Fires:

- FooTable.event:Sorting"before.ft.sorting"
- FooTable.event:Sorting"after.ft.sorting"

##### Returns:

Type
  jQuery.Promise