mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Fix for strange table filtering bug
- When a table was "refreshed" based on the selectable filters, table ordering was not observed - This was due to the original query parameter conversion not being observed - Refactored out the conversion function so it works correctly now - Also removed some cruft from generated query strings
This commit is contained in:
parent
19ba9bf93c
commit
9d7f9a9aa3
@ -314,7 +314,7 @@ function setupFilterList(tableKey, table, target) {
|
|||||||
// Only add the new filter if it is not empty!
|
// Only add the new filter if it is not empty!
|
||||||
if (tag && tag.length > 0) {
|
if (tag && tag.length > 0) {
|
||||||
var filters = addTableFilter(tableKey, tag, val);
|
var filters = addTableFilter(tableKey, tag, val);
|
||||||
reloadTable(table, filters);
|
reloadTableFilters(table, filters);
|
||||||
|
|
||||||
// Run this function again
|
// Run this function again
|
||||||
setupFilterList(tableKey, table, target);
|
setupFilterList(tableKey, table, target);
|
||||||
@ -333,7 +333,7 @@ function setupFilterList(tableKey, table, target) {
|
|||||||
element.find(`#${clear}`).click(function() {
|
element.find(`#${clear}`).click(function() {
|
||||||
var filters = clearTableFilters(tableKey);
|
var filters = clearTableFilters(tableKey);
|
||||||
|
|
||||||
reloadTable(table, filters);
|
reloadTableFilters(table, filters);
|
||||||
|
|
||||||
setupFilterList(tableKey, table, target);
|
setupFilterList(tableKey, table, target);
|
||||||
});
|
});
|
||||||
@ -346,7 +346,7 @@ function setupFilterList(tableKey, table, target) {
|
|||||||
|
|
||||||
var filters = removeTableFilter(tableKey, filter);
|
var filters = removeTableFilter(tableKey, filter);
|
||||||
|
|
||||||
reloadTable(table, filters);
|
reloadTableFilters(table, filters);
|
||||||
|
|
||||||
// Run this function again!
|
// Run this function again!
|
||||||
setupFilterList(tableKey, table, target);
|
setupFilterList(tableKey, table, target);
|
||||||
|
@ -68,7 +68,7 @@ function isNumeric(n) {
|
|||||||
* Reload a table which has already been made into a bootstrap table.
|
* Reload a table which has already been made into a bootstrap table.
|
||||||
* New filters can be optionally provided, to change the query params.
|
* New filters can be optionally provided, to change the query params.
|
||||||
*/
|
*/
|
||||||
function reloadTable(table, filters) {
|
function reloadTableFilters(table, filters) {
|
||||||
|
|
||||||
// Simply perform a refresh
|
// Simply perform a refresh
|
||||||
if (filters == null) {
|
if (filters == null) {
|
||||||
@ -94,16 +94,11 @@ function reloadTable(table, filters) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
options.queryParams = function(tableParams) {
|
options.queryParams = function(tableParams) {
|
||||||
|
return convertQueryParameters(tableParams, params);
|
||||||
for (key in params) {
|
};
|
||||||
tableParams[key] = params[key];
|
|
||||||
}
|
|
||||||
|
|
||||||
return tableParams;
|
|
||||||
}
|
|
||||||
|
|
||||||
table.bootstrapTable('refreshOptions', options);
|
table.bootstrapTable('refreshOptions', options);
|
||||||
table.bootstrapTable('refresh');
|
table.bootstrapTable('refresh', filters);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -122,31 +117,10 @@ function visibleColumnString(columns) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Wrapper function for bootstrapTable.
|
/*
|
||||||
* Sets some useful defaults, and manage persistent settings.
|
* Convert bootstrap-table style parameters to "InvenTree" style
|
||||||
*/
|
*/
|
||||||
$.fn.inventreeTable = function(options) {
|
function convertQueryParameters(params, filters) {
|
||||||
|
|
||||||
var table = this;
|
|
||||||
|
|
||||||
var tableName = options.name || 'table';
|
|
||||||
|
|
||||||
var varName = tableName + '-pagesize';
|
|
||||||
|
|
||||||
// Pagingation options (can be server-side or client-side as specified by the caller)
|
|
||||||
if (!options.disablePagination) {
|
|
||||||
options.pagination = true;
|
|
||||||
options.paginationVAlign = options.paginationVAlign || 'both';
|
|
||||||
options.pageSize = inventreeLoad(varName, 25);
|
|
||||||
options.pageList = [25, 50, 100, 250, 'all'];
|
|
||||||
options.totalField = 'count';
|
|
||||||
options.dataField = 'results';
|
|
||||||
}
|
|
||||||
|
|
||||||
// Extract query params
|
|
||||||
var filters = options.queryParams || options.filters || {};
|
|
||||||
|
|
||||||
options.queryParams = function(params) {
|
|
||||||
|
|
||||||
// Override the way that we ask the server to sort results
|
// Override the way that we ask the server to sort results
|
||||||
// It seems bootstrap-table does not offer a "native" way to do this...
|
// It seems bootstrap-table does not offer a "native" way to do this...
|
||||||
@ -178,9 +152,48 @@ $.fn.inventreeTable = function(options) {
|
|||||||
if ('order' in filters) {
|
if ('order' in filters) {
|
||||||
params['order'] = filters['order'];
|
params['order'] = filters['order'];
|
||||||
}
|
}
|
||||||
return params;
|
|
||||||
|
// Remove searchable[] array (generated by bootstrap-table)
|
||||||
|
if ('searchable' in params) {
|
||||||
|
delete params['searchable'];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ('sortable' in params) {
|
||||||
|
delete params['sortable'];
|
||||||
|
}
|
||||||
|
|
||||||
|
return params;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* Wrapper function for bootstrapTable.
|
||||||
|
* Sets some useful defaults, and manage persistent settings.
|
||||||
|
*/
|
||||||
|
$.fn.inventreeTable = function(options) {
|
||||||
|
|
||||||
|
var table = this;
|
||||||
|
|
||||||
|
var tableName = options.name || 'table';
|
||||||
|
|
||||||
|
var varName = tableName + '-pagesize';
|
||||||
|
|
||||||
|
// Pagingation options (can be server-side or client-side as specified by the caller)
|
||||||
|
if (!options.disablePagination) {
|
||||||
|
options.pagination = true;
|
||||||
|
options.paginationVAlign = options.paginationVAlign || 'both';
|
||||||
|
options.pageSize = inventreeLoad(varName, 25);
|
||||||
|
options.pageList = [25, 50, 100, 250, 'all'];
|
||||||
|
options.totalField = 'count';
|
||||||
|
options.dataField = 'results';
|
||||||
|
}
|
||||||
|
|
||||||
|
// Extract query params
|
||||||
|
var filters = options.queryParams || options.filters || {};
|
||||||
|
|
||||||
|
options.queryParams = function(params) {
|
||||||
|
return convertQueryParameters(params, filters);
|
||||||
|
};
|
||||||
|
|
||||||
options.rememberOrder = true;
|
options.rememberOrder = true;
|
||||||
|
|
||||||
if (options.sortable == null) {
|
if (options.sortable == null) {
|
||||||
|
Loading…
Reference in New Issue
Block a user