Skip to content
This repository was archived by the owner on Jun 4, 2024. It is now read-only.

Commit

Permalink
Merge pull request #417 from plotly/sort-by
Browse files Browse the repository at this point in the history
change sorting_settings to sort_by
  • Loading branch information
alexcjohnson authored Apr 25, 2019
2 parents 989d8cd + 5410f92 commit 23c6b84
Show file tree
Hide file tree
Showing 11 changed files with 61 additions and 58 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ This project adheres to [Semantic Versioning](http://semver.org/).
[#397](https://github.com/plotly/dash-table/pull/397)
- Rename `filtering_settings` to `filter`

[#412](https://github.com/plotly/dash-table/pull/412)
- Rename `sorting_settings` to `sort_by`

## [3.6.0] - 2019-03-04
### Fixed
[#189](https://github.com/plotly/dash-table/issues/189)
Expand Down
4 changes: 2 additions & 2 deletions src/dash-table/components/ControlledTable/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,7 @@ export default class ControlledTable extends PureComponent<ControlledTableProps>
editable,
filter,
setProps,
sorting_settings,
sort_by,
viewport
} = this.props;

Expand All @@ -552,7 +552,7 @@ export default class ControlledTable extends PureComponent<ControlledTableProps>
columns,
data,
true,
!sorting_settings.length || !filter.length
!sort_by.length || !filter.length
);

if (result) {
Expand Down
8 changes: 4 additions & 4 deletions src/dash-table/components/HeaderFactory.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@ export default class HeaderFactory {
public createHeaders() {
const props = this.props;

let {
const {
columns,
merge_duplicate_headers,
pagination_mode,
row_deletable,
row_selectable,
setProps,
sorting,
sorting_settings,
sort_by,
sorting_type,
style_cell,
style_cell_conditional,
Expand Down Expand Up @@ -85,7 +85,7 @@ export default class HeaderFactory {
labelsAndIndices,
sorting,
sorting_type,
sorting_settings,
sort_by,
pagination_mode,
setProps,
props
Expand All @@ -99,4 +99,4 @@ export default class HeaderFactory {

return arrayMap(operations, headers, (o, h) => Array.prototype.concat(o, h));
}
}
}
10 changes: 5 additions & 5 deletions src/dash-table/components/Table/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export default class Table extends Component<PropsWithDefaultsAndDerived, Standa
pagination_settings,
selected_rows,
sorting,
sorting_settings,
sort_by,
sorting_treat_empty_string_as_none,
uiCell,
uiHeaders,
Expand All @@ -89,7 +89,7 @@ export default class Table extends Component<PropsWithDefaultsAndDerived, Standa
filtering,
filter,
sorting,
sorting_settings,
sort_by,
sorting_treat_empty_string_as_none
);

Expand Down Expand Up @@ -151,7 +151,7 @@ export default class Table extends Component<PropsWithDefaultsAndDerived, Standa
pagination_mode,
pagination_settings,
sorting,
sorting_settings,
sort_by,
viewport,
viewport_selected_rows,
virtual,
Expand All @@ -168,7 +168,7 @@ export default class Table extends Component<PropsWithDefaultsAndDerived, Standa

const invalidatedFilter = this.filterCache(filter);
const invalidatedPagination = this.paginationCache(pagination_settings);
const invalidatedSort = this.sortCache(sorting_settings);
const invalidatedSort = this.sortCache(sort_by);

const invalidateSelection =
(!invalidatedFilter.cached && !invalidatedFilter.first && filtering === 'be') ||
Expand Down Expand Up @@ -272,4 +272,4 @@ export default class Table extends Component<PropsWithDefaultsAndDerived, Standa
private readonly structuredQueryCache = memoizeOneWithFlag(
(query: string) => new QuerySyntaxTree(query).toStructure()
);
}
}
4 changes: 2 additions & 2 deletions src/dash-table/components/Table/props.ts
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ interface IProps {
selected_rows?: Indices;
setProps?: SetProps;
sorting?: Sorting;
sorting_settings?: SortSettings;
sort_by?: SortSettings;
sorting_type?: SortingType;
sorting_treat_empty_string_as_none?: boolean;
style_as_list_view?: boolean;
Expand Down Expand Up @@ -322,7 +322,7 @@ interface IDefaultProps {
selected_cells: SelectedCells;
selected_rows: number[];
sorting: Sorting;
sorting_settings: SortSettings;
sort_by: SortSettings;
sorting_type: SortingType;
sorting_treat_empty_string_as_none: boolean;
style_as_list_view: boolean;
Expand Down
8 changes: 4 additions & 4 deletions src/dash-table/dash/DataTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export const defaultProps = {
filtering_types: ['basic'],
sorting: false,
sorting_type: 'single',
sorting_settings: [],
sort_by: [],
style_as_list_view: false,

derived_viewport_data: [],
Expand Down Expand Up @@ -831,7 +831,7 @@ export const propTypes = {
* with the `fe` (or True) setting or via a callback in your
* python "back-end" with the `be` setting.
* Clicking on the sort arrows will update the
* `sorting_settings` property.
* `sort_by` property.
*/
sorting: PropTypes.oneOf(['fe', 'be', true, false]),

Expand All @@ -848,7 +848,7 @@ export const propTypes = {
sorting_type: PropTypes.oneOf(['single', 'multi']),

/**
* `sorting_settings` describes the current state
* `sort_by` describes the current state
* of the sorting UI.
* That is, if the user clicked on the sort arrow
* of a column, then this property will be updated
Expand All @@ -858,7 +858,7 @@ export const propTypes = {
* sorting parameters, in the order in which they were
* clicked.
*/
sorting_settings: PropTypes.arrayOf(
sort_by: PropTypes.arrayOf(
// .exact
PropTypes.shape({
column_id: PropTypes.oneOfType([PropTypes.string, PropTypes.number]).isRequired,
Expand Down
4 changes: 2 additions & 2 deletions src/dash-table/derived/data/virtual.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const getter = (
filtering: Filtering,
filter: string,
sorting: Sorting,
sorting_settings: SortSettings = [],
sort_by: SortSettings = [],
sorting_treat_empty_string_as_none: boolean
): IDerivedData => {
const map = new Map<Datum, number>();
Expand All @@ -37,7 +37,7 @@ const getter = (
undefined;

if (sorting === 'fe' || sorting === true) {
data = sort(data, sorting_settings, isNully);
data = sort(data, sort_by, isNully);
}

// virtual_indices
Expand Down
2 changes: 1 addition & 1 deletion src/dash-table/derived/header/content.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ function doSort(columnId: ColumnId, sortSettings: SortSettings, sortType: Sortin
multiUpdateSettings;

setProps({
sorting_settings: sortingStrategy(
sort_by: sortingStrategy(
sortSettings,
{ column_id: columnId, direction }
)
Expand Down
14 changes: 7 additions & 7 deletions tests/cypress/dash/v_be_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@

@app.callback(Output("table", "data"), [
Input("table", "pagination_settings"),
Input("table", "sorting_settings")
Input("table", "sort_by")
])
def updateData(pagination_settings, sorting_settings):
def updateData(pagination_settings, sort_by):
print(pagination_settings)

current_page = pagination_settings["current_page"]
Expand All @@ -75,14 +75,14 @@ def updateData(pagination_settings, sorting_settings):
start_index = current_page * page_size
end_index = start_index + page_size
print(str(start_index) + "," + str(end_index))
print(sorting_settings)
print(sort_by)

if (sorting_settings is None or len(sorting_settings) == 0):
if (sort_by is None or len(sort_by) == 0):
sorted_df = df.values
else:
sorted_df = df.sort_index(
axis=sorting_settings[0]['column_id'],
ascending=(sorting_settings[0]['direction'] == 'asc')
axis=sort_by[0]['column_id'],
ascending=(sort_by[0]['direction'] == 'asc')
).values

return sorted_df[start_index:end_index]
Expand All @@ -109,4 +109,4 @@ def findModifiedValue(data, previous):


if __name__ == "__main__":
app.run_server(port=8081, debug=False)
app.run_server(port=8081, debug=False)
52 changes: 26 additions & 26 deletions tests/dash/app_dataframe_backend_paging.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def layout():

sorting='be',
sorting_type='single',
sorting_settings=[]
sort_by=[]
),

section_title('Backend Paging with Multi Column Sorting'),
Expand All @@ -104,7 +104,7 @@ def layout():

sorting='be',
sorting_type='multi',
sorting_settings=[]
sort_by=[]
),

section_title('Backend Paging with Filtering'),
Expand Down Expand Up @@ -162,7 +162,7 @@ def layout():

sorting='be',
sorting_type='multi',
sorting_settings=[]
sort_by=[]
),

section_title('Connecting Backend Paging with a Graph'),
Expand Down Expand Up @@ -192,7 +192,7 @@ def layout():

sorting='be',
sorting_type='multi',
sorting_settings=[]
sort_by=[]
),
style={'height': 750, 'overflowY': 'scroll'},
className='six columns'
Expand Down Expand Up @@ -221,13 +221,13 @@ def update_graph(pagination_settings):
@app.callback(
Output(IDS["table-sorting"], "data"),
[Input(IDS["table-sorting"], "pagination_settings"),
Input(IDS["table-sorting"], "sorting_settings")])
def update_graph(pagination_settings, sorting_settings):
print(sorting_settings)
if len(sorting_settings):
Input(IDS["table-sorting"], "sort_by")])
def update_graph(pagination_settings, sort_by):
print(sort_by)
if len(sort_by):
dff = df.sort_values(
sorting_settings[0]['columnId'],
ascending=sorting_settings[0]['direction'] == 'asc',
sort_by[0]['columnId'],
ascending=sort_by[0]['direction'] == 'asc',
inplace=False
)
else:
Expand All @@ -244,15 +244,15 @@ def update_graph(pagination_settings, sorting_settings):
@app.callback(
Output(IDS["table-multi-sorting"], "data"),
[Input(IDS["table-multi-sorting"], "pagination_settings"),
Input(IDS["table-multi-sorting"], "sorting_settings")])
def update_graph(pagination_settings, sorting_settings):
print(sorting_settings)
if len(sorting_settings):
Input(IDS["table-multi-sorting"], "sort_by")])
def update_graph(pagination_settings, sort_by):
print(sort_by)
if len(sort_by):
dff = df.sort_values(
[col['columnId'] for col in sorting_settings],
[col['columnId'] for col in sort_by],
ascending=[
col['direction'] == 'asc'
for col in sorting_settings
for col in sort_by
],
inplace=False
)
Expand Down Expand Up @@ -297,9 +297,9 @@ def update_graph(pagination_settings, filter):
@app.callback(
Output(IDS["table-sorting-filtering"], "data"),
[Input(IDS["table-sorting-filtering"], "pagination_settings"),
Input(IDS["table-sorting-filtering"], "sorting_settings"),
Input(IDS["table-sorting-filtering"], "sort_by"),
Input(IDS["table-sorting-filtering"], "filter")])
def update_graph(pagination_settings, sorting_settings, filter):
def update_graph(pagination_settings, sort_by, filter):
filtering_expressions = filter.split(' && ')
dff = df
for filter in filtering_expressions:
Expand All @@ -316,12 +316,12 @@ def update_graph(pagination_settings, sorting_settings, filter):
filter_value = float(filter.split(' < ')[1])
dff = dff.loc[dff[col_name] < filter_value]

if len(sorting_settings):
if len(sort_by):
dff = dff.sort_values(
[col['columnId'] for col in sorting_settings],
[col['columnId'] for col in sort_by],
ascending=[
col['direction'] == 'asc'
for col in sorting_settings
for col in sort_by
],
inplace=False
)
Expand All @@ -335,9 +335,9 @@ def update_graph(pagination_settings, sorting_settings, filter):
@app.callback(
Output(IDS["table-paging-with-graph"], "data"),
[Input(IDS["table-paging-with-graph"], "pagination_settings"),
Input(IDS["table-paging-with-graph"], "sorting_settings"),
Input(IDS["table-paging-with-graph"], "sort_by"),
Input(IDS["table-paging-with-graph"], "filter")])
def update_table(pagination_settings, sorting_settings, filter):
def update_table(pagination_settings, sort_by, filter):
filtering_expressions = filter.split(' && ')
dff = df
for filter in filtering_expressions:
Expand All @@ -354,12 +354,12 @@ def update_table(pagination_settings, sorting_settings, filter):
filter_value = float(filter.split(' < ')[1])
dff = dff.loc[dff[col_name] < filter_value]

if len(sorting_settings):
if len(sort_by):
dff = dff.sort_values(
[col['columnId'] for col in sorting_settings],
[col['columnId'] for col in sort_by],
ascending=[
col['direction'] == 'asc'
for col in sorting_settings
for col in sort_by
],
inplace=False
)
Expand Down
Loading

0 comments on commit 23c6b84

Please sign in to comment.