mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Merge pull request #939 from SchrodingersGat/column-remembering
Make checkbox field non-switchable for stock table
This commit is contained in:
commit
baaabd00d6
@ -80,11 +80,28 @@ function reloadTable(table, filters) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function visibleColumnString(columns) {
|
||||||
|
/* Generate a list of "visible" columns to save to file. */
|
||||||
|
|
||||||
|
var fields = [];
|
||||||
|
|
||||||
|
columns.forEach(function(column) {
|
||||||
|
if (column.switchable && column.visible) {
|
||||||
|
fields.push(column.field);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return fields.join(',');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Wrapper function for bootstrapTable.
|
/* Wrapper function for bootstrapTable.
|
||||||
* Sets some useful defaults, and manage persistent settings.
|
* Sets some useful defaults, and manage persistent settings.
|
||||||
*/
|
*/
|
||||||
$.fn.inventreeTable = function(options) {
|
$.fn.inventreeTable = function(options) {
|
||||||
|
|
||||||
|
var table = this;
|
||||||
|
|
||||||
var tableName = options.name || 'table';
|
var tableName = options.name || 'table';
|
||||||
|
|
||||||
var varName = tableName + '-pagesize';
|
var varName = tableName + '-pagesize';
|
||||||
@ -95,14 +112,51 @@ $.fn.inventreeTable = function(options) {
|
|||||||
options.rememberOrder = true;
|
options.rememberOrder = true;
|
||||||
options.sortable = true;
|
options.sortable = true;
|
||||||
options.search = true;
|
options.search = true;
|
||||||
|
options.showColumns = true;
|
||||||
|
|
||||||
// Callback to save pagination data
|
// Callback to save pagination data
|
||||||
options.onPageChange = function(number, size) {
|
options.onPageChange = function(number, size) {
|
||||||
inventreeSave(varName, size);
|
inventreeSave(varName, size);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Callback when a column is changed
|
||||||
|
options.onColumnSwitch = function(field, checked) {
|
||||||
|
console.log(`${field} -> ${checked}`);
|
||||||
|
|
||||||
|
var columns = table.bootstrapTable('getVisibleColumns');
|
||||||
|
|
||||||
|
var text = visibleColumnString(columns);
|
||||||
|
|
||||||
|
// Save visible columns
|
||||||
|
inventreeSave(`table_columns_${tableName}`, text);
|
||||||
|
};
|
||||||
|
|
||||||
// Standard options for all tables
|
// Standard options for all tables
|
||||||
this.bootstrapTable(options);
|
table.bootstrapTable(options);
|
||||||
|
|
||||||
|
// Load visible column list from memory
|
||||||
|
// Load visible column list
|
||||||
|
var visibleColumns = inventreeLoad(`table_columns_${tableName}`, null);
|
||||||
|
|
||||||
|
// If a set of visible columns has been saved, load!
|
||||||
|
if (visibleColumns) {
|
||||||
|
var columns = visibleColumns.split(",");
|
||||||
|
|
||||||
|
// Which columns are currently visible?
|
||||||
|
var visible = table.bootstrapTable('getVisibleColumns');
|
||||||
|
|
||||||
|
if (visible) {
|
||||||
|
visible.forEach(function(column) {
|
||||||
|
|
||||||
|
// Visible field should *not* be visible! (hide it!)
|
||||||
|
if (column.switchable && !columns.includes(column.field)) {
|
||||||
|
table.bootstrapTable('hideColumn', column.field);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
console.log('Could not get list of visible columns!');
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function customGroupSorter(sortName, sortOrder, sortData) {
|
function customGroupSorter(sortName, sortOrder, sortData) {
|
||||||
|
@ -127,6 +127,7 @@ function setupCallbacks() {
|
|||||||
|
|
||||||
$("#po-table").inventreeTable({
|
$("#po-table").inventreeTable({
|
||||||
onPostBody: setupCallbacks,
|
onPostBody: setupCallbacks,
|
||||||
|
name: 'purchaseorder',
|
||||||
formatNoMatches: function() { return "{% trans 'No line items found' %}"; },
|
formatNoMatches: function() { return "{% trans 'No line items found' %}"; },
|
||||||
queryParams: {
|
queryParams: {
|
||||||
order: {{ order.id }},
|
order: {{ order.id }},
|
||||||
@ -138,6 +139,7 @@ $("#po-table").inventreeTable({
|
|||||||
field: 'pk',
|
field: 'pk',
|
||||||
title: 'ID',
|
title: 'ID',
|
||||||
visible: false,
|
visible: false,
|
||||||
|
switchable: false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
field: 'part',
|
field: 'part',
|
||||||
|
@ -190,6 +190,7 @@ $("#so-lines-table").inventreeTable({
|
|||||||
field: 'pk',
|
field: 'pk',
|
||||||
title: 'ID',
|
title: 'ID',
|
||||||
visible: false,
|
visible: false,
|
||||||
|
switchable: false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
sortable: true,
|
sortable: true,
|
||||||
|
@ -29,6 +29,7 @@
|
|||||||
field: 'pk',
|
field: 'pk',
|
||||||
title: 'ID',
|
title: 'ID',
|
||||||
visible: false,
|
visible: false,
|
||||||
|
switchable: false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
field: 'part_detail',
|
field: 'part_detail',
|
||||||
|
@ -37,6 +37,7 @@
|
|||||||
field: 'pk',
|
field: 'pk',
|
||||||
title: 'ID',
|
title: 'ID',
|
||||||
visible: false,
|
visible: false,
|
||||||
|
switchable: false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
field: 'symbol',
|
field: 'symbol',
|
||||||
|
@ -31,6 +31,7 @@
|
|||||||
field: 'pk',
|
field: 'pk',
|
||||||
title: 'ID',
|
title: 'ID',
|
||||||
visible: false,
|
visible: false,
|
||||||
|
switchable: false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
field: 'name',
|
field: 'name',
|
||||||
|
@ -111,6 +111,7 @@ function loadBomTable(table, options) {
|
|||||||
field: 'pk',
|
field: 'pk',
|
||||||
title: 'ID',
|
title: 'ID',
|
||||||
visible: false,
|
visible: false,
|
||||||
|
switchable: false,
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
@ -320,6 +321,7 @@ function loadBomTable(table, options) {
|
|||||||
parentIdField: 'parentId',
|
parentIdField: 'parentId',
|
||||||
treeShowField: 'sub_part',
|
treeShowField: 'sub_part',
|
||||||
showColumns: true,
|
showColumns: true,
|
||||||
|
name: 'bom',
|
||||||
sortable: true,
|
sortable: true,
|
||||||
search: true,
|
search: true,
|
||||||
rowStyle: function(row, index) {
|
rowStyle: function(row, index) {
|
||||||
|
@ -21,12 +21,14 @@ function loadBuildTable(table, options) {
|
|||||||
url: options.url,
|
url: options.url,
|
||||||
queryParams: filters,
|
queryParams: filters,
|
||||||
groupBy: false,
|
groupBy: false,
|
||||||
|
name: 'builds',
|
||||||
original: params,
|
original: params,
|
||||||
columns: [
|
columns: [
|
||||||
{
|
{
|
||||||
field: 'pk',
|
field: 'pk',
|
||||||
title: 'ID',
|
title: 'ID',
|
||||||
visible: false,
|
visible: false,
|
||||||
|
switchable: false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
field: 'title',
|
field: 'title',
|
||||||
|
@ -27,16 +27,20 @@ function loadCompanyTable(table, url, options={}) {
|
|||||||
queryParams: filters,
|
queryParams: filters,
|
||||||
groupBy: false,
|
groupBy: false,
|
||||||
formatNoMatches: function() { return "{% trans "No company information found" %}"; },
|
formatNoMatches: function() { return "{% trans "No company information found" %}"; },
|
||||||
|
showColumns: true,
|
||||||
|
name: 'company',
|
||||||
columns: [
|
columns: [
|
||||||
{
|
{
|
||||||
field: 'pk',
|
field: 'pk',
|
||||||
title: 'ID',
|
title: 'ID',
|
||||||
visible: false,
|
visible: false,
|
||||||
|
switchable: false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
field: 'name',
|
field: 'name',
|
||||||
title: '{% trans "Company" %}',
|
title: '{% trans "Company" %}',
|
||||||
sortable: true,
|
sortable: true,
|
||||||
|
switchable: false,
|
||||||
formatter: function(value, row, index, field) {
|
formatter: function(value, row, index, field) {
|
||||||
var html = imageHoverIcon(row.image) + renderLink(value, row.url);
|
var html = imageHoverIcon(row.image) + renderLink(value, row.url);
|
||||||
|
|
||||||
@ -97,11 +101,13 @@ function loadSupplierPartTable(table, url, options) {
|
|||||||
url: url,
|
url: url,
|
||||||
method: 'get',
|
method: 'get',
|
||||||
queryParams: filters,
|
queryParams: filters,
|
||||||
|
name: 'supplierparts',
|
||||||
groupBy: false,
|
groupBy: false,
|
||||||
formatNoMatches: function() { return "{% trans "No supplier parts found" %}"; },
|
formatNoMatches: function() { return "{% trans "No supplier parts found" %}"; },
|
||||||
columns: [
|
columns: [
|
||||||
{
|
{
|
||||||
checkbox: true,
|
checkbox: true,
|
||||||
|
switchable: false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
sortable: true,
|
sortable: true,
|
||||||
|
@ -121,6 +121,7 @@ function loadPurchaseOrderTable(table, options) {
|
|||||||
$(table).inventreeTable({
|
$(table).inventreeTable({
|
||||||
url: options.url,
|
url: options.url,
|
||||||
queryParams: filters,
|
queryParams: filters,
|
||||||
|
name: 'purchaseorder',
|
||||||
groupBy: false,
|
groupBy: false,
|
||||||
original: options.params,
|
original: options.params,
|
||||||
formatNoMatches: function() { return "{% trans "No purchase orders found" %}"; },
|
formatNoMatches: function() { return "{% trans "No purchase orders found" %}"; },
|
||||||
@ -129,6 +130,7 @@ function loadPurchaseOrderTable(table, options) {
|
|||||||
field: 'pk',
|
field: 'pk',
|
||||||
title: 'ID',
|
title: 'ID',
|
||||||
visible: false,
|
visible: false,
|
||||||
|
switchable: false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
sortable: true,
|
sortable: true,
|
||||||
@ -194,6 +196,7 @@ function loadSalesOrderTable(table, options) {
|
|||||||
$(table).inventreeTable({
|
$(table).inventreeTable({
|
||||||
url: options.url,
|
url: options.url,
|
||||||
queryParams: filters,
|
queryParams: filters,
|
||||||
|
name: 'salesorder',
|
||||||
groupBy: false,
|
groupBy: false,
|
||||||
original: options.params,
|
original: options.params,
|
||||||
formatNoMatches: function() { return "{% trans "No sales orders found" %}"; },
|
formatNoMatches: function() { return "{% trans "No sales orders found" %}"; },
|
||||||
@ -202,6 +205,7 @@ function loadSalesOrderTable(table, options) {
|
|||||||
field: 'pk',
|
field: 'pk',
|
||||||
title: 'ID',
|
title: 'ID',
|
||||||
visible: false,
|
visible: false,
|
||||||
|
switchable: false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
sortable: true,
|
sortable: true,
|
||||||
|
@ -237,6 +237,7 @@ function loadPartTable(table, url, options={}) {
|
|||||||
method: 'get',
|
method: 'get',
|
||||||
queryParams: filters,
|
queryParams: filters,
|
||||||
groupBy: false,
|
groupBy: false,
|
||||||
|
name: 'part',
|
||||||
original: params,
|
original: params,
|
||||||
formatNoMatches: function() { return "{% trans "No parts found" %}"; },
|
formatNoMatches: function() { return "{% trans "No parts found" %}"; },
|
||||||
columns: columns,
|
columns: columns,
|
||||||
@ -338,6 +339,7 @@ function loadPartTestTemplateTable(table, options) {
|
|||||||
},
|
},
|
||||||
url: "{% url 'api-part-test-template-list' %}",
|
url: "{% url 'api-part-test-template-list' %}",
|
||||||
queryParams: filters,
|
queryParams: filters,
|
||||||
|
name: 'testtemplate',
|
||||||
original: original,
|
original: original,
|
||||||
columns: [
|
columns: [
|
||||||
{
|
{
|
||||||
|
@ -73,6 +73,7 @@ function loadStockTestResultsTable(table, options) {
|
|||||||
table.inventreeTable({
|
table.inventreeTable({
|
||||||
url: "{% url 'api-part-test-template-list' %}",
|
url: "{% url 'api-part-test-template-list' %}",
|
||||||
method: 'get',
|
method: 'get',
|
||||||
|
name: 'testresult',
|
||||||
formatNoMatches: function() {
|
formatNoMatches: function() {
|
||||||
return "{% trans 'No test results found' %}";
|
return "{% trans 'No test results found' %}";
|
||||||
},
|
},
|
||||||
@ -84,6 +85,7 @@ function loadStockTestResultsTable(table, options) {
|
|||||||
field: 'pk',
|
field: 'pk',
|
||||||
title: 'ID',
|
title: 'ID',
|
||||||
visible: false,
|
visible: false,
|
||||||
|
switchable: false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
field: 'test_name',
|
field: 'test_name',
|
||||||
@ -264,6 +266,7 @@ function loadStockTable(table, options) {
|
|||||||
queryParams: filters,
|
queryParams: filters,
|
||||||
customSort: customGroupSorter,
|
customSort: customGroupSorter,
|
||||||
groupBy: true,
|
groupBy: true,
|
||||||
|
name: 'stock',
|
||||||
original: original,
|
original: original,
|
||||||
showColumns: true,
|
showColumns: true,
|
||||||
groupByField: options.groupByField || 'part',
|
groupByField: options.groupByField || 'part',
|
||||||
@ -405,6 +408,7 @@ function loadStockTable(table, options) {
|
|||||||
checkbox: true,
|
checkbox: true,
|
||||||
title: '{% trans "Select" %}',
|
title: '{% trans "Select" %}',
|
||||||
searchable: false,
|
searchable: false,
|
||||||
|
switchable: false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
field: 'pk',
|
field: 'pk',
|
||||||
|
Loading…
Reference in New Issue
Block a user