mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Store table query parameters when performing a bootstrap-table query
- For now it only supports .csv format
This commit is contained in:
parent
549f16b7aa
commit
6b7a0fde1b
@ -240,12 +240,7 @@
|
|||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
$("#stock-export").click(function() {
|
$("#stock-export").click(function() {
|
||||||
|
downloadTableData($('#stock-table'));
|
||||||
exportStock({
|
|
||||||
{% if location %}
|
|
||||||
location: {{ location.pk }}
|
|
||||||
{% endif %}
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
$('#location-create').click(function () {
|
$('#location-create').click(function () {
|
||||||
|
@ -7,6 +7,7 @@
|
|||||||
|
|
||||||
/* exported
|
/* exported
|
||||||
customGroupSorter,
|
customGroupSorter,
|
||||||
|
downloadTableData,
|
||||||
reloadtable,
|
reloadtable,
|
||||||
renderLink,
|
renderLink,
|
||||||
reloadTableFilters,
|
reloadTableFilters,
|
||||||
@ -21,6 +22,42 @@ function reloadtable(table) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Download data from a table, via the API.
|
||||||
|
* This requires a number of conditions to be met:
|
||||||
|
*
|
||||||
|
* - The API endpoint supports data download (on the server side)
|
||||||
|
* - The table is "flat" (does not support multi-level loading, etc)
|
||||||
|
* - The table has been loaded using the inventreeTable() function, not bootstrapTable()
|
||||||
|
* (Refer to the "reloadTableFilters" function to see why!)
|
||||||
|
*/
|
||||||
|
function downloadTableData(table) {
|
||||||
|
|
||||||
|
// Extract table configuration options
|
||||||
|
var options = table.bootstrapTable('getOptions');
|
||||||
|
|
||||||
|
var url = options.url;
|
||||||
|
|
||||||
|
if (!url) {
|
||||||
|
console.log("Error: downloadTableData could not find 'url' parameter");
|
||||||
|
}
|
||||||
|
|
||||||
|
var query_params = options.query_params || {};
|
||||||
|
|
||||||
|
url += '?';
|
||||||
|
|
||||||
|
for (const [key, value] of Object.entries(query_params)) {
|
||||||
|
url += `${key}=${value}&`;
|
||||||
|
}
|
||||||
|
|
||||||
|
var format = 'csv';
|
||||||
|
|
||||||
|
url += `export=${format}`;
|
||||||
|
|
||||||
|
location.href = url;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Render a URL for display
|
* Render a URL for display
|
||||||
* @param {String} text
|
* @param {String} text
|
||||||
@ -114,6 +151,10 @@ function reloadTableFilters(table, filters) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Store the total set of query params
|
||||||
|
// This is necessary for the "downloadTableData" function to work
|
||||||
|
options.query_params = params;
|
||||||
|
|
||||||
options.queryParams = function(tableParams) {
|
options.queryParams = function(tableParams) {
|
||||||
return convertQueryParameters(tableParams, params);
|
return convertQueryParameters(tableParams, params);
|
||||||
};
|
};
|
||||||
@ -221,7 +262,11 @@ $.fn.inventreeTable = function(options) {
|
|||||||
// Extract query params
|
// Extract query params
|
||||||
var filters = options.queryParams || options.filters || {};
|
var filters = options.queryParams || options.filters || {};
|
||||||
|
|
||||||
|
// Store the total set of query params
|
||||||
|
options.query_params = filters;
|
||||||
|
|
||||||
options.queryParams = function(params) {
|
options.queryParams = function(params) {
|
||||||
|
// Update the query parameters callback with the *new* filters
|
||||||
return convertQueryParameters(params, filters);
|
return convertQueryParameters(params, filters);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user