Hide result types which return no results

This commit is contained in:
Oliver Walters 2019-06-02 20:28:17 +10:00
parent 0b88953706
commit 64d541f453
4 changed files with 92 additions and 74 deletions

View File

@ -156,6 +156,7 @@
{% endif %}
},
buttons: ['#part-options'],
checkbox: true,
},
);

View File

@ -82,6 +82,7 @@ function loadPartTable(table, url, options={}) {
* - url: Base URL for API query
* - options: object containing following (optional) fields
* allowInactive: If true, allow display of inactive parts
* checkbox: Show the checkbox column
* query: extra query params for API request
* buttons: If provided, link buttons to selection status of this table
*/
@ -94,31 +95,23 @@ function loadPartTable(table, url, options={}) {
query.active = true;
}
$(table).bootstrapTable({
url: url,
sortable: true,
search: true,
sortName: 'name',
method: 'get',
pagination: true,
pageSize: 25,
rememberOrder: true,
formatNoMatches: function() { return "No parts found"; },
queryParams: function(p) {
return query;
},
columns: [
{
checkbox: true,
title: 'Select',
searchable: false,
},
var columns = [
{
field: 'pk',
title: 'ID',
visible: false,
},
{
}
];
if (options.checkbox) {
columns.push({
checkbox: true,
title: 'Select',
searchable: false,
});
}
columns.push({
field: 'full_name',
title: 'Part',
sortable: true,
@ -135,8 +128,9 @@ function loadPartTable(table, url, options={}) {
}
return display;
}
},
{
});
columns.push({
sortable: true,
field: 'description',
title: 'Description',
@ -148,8 +142,9 @@ function loadPartTable(table, url, options={}) {
return value;
}
},
{
});
columns.push({
sortable: true,
field: 'category_name',
title: 'Category',
@ -161,8 +156,9 @@ function loadPartTable(table, url, options={}) {
return '';
}
}
},
{
});
columns.push({
field: 'total_stock',
title: 'Stock',
searchable: false,
@ -175,8 +171,22 @@ function loadPartTable(table, url, options={}) {
return "<span class='label label-warning'>No Stock</span>";
}
}
}
],
});
$(table).bootstrapTable({
url: url,
sortable: true,
search: true,
sortName: 'name',
method: 'get',
pagination: true,
pageSize: 25,
rememberOrder: true,
formatNoMatches: function() { return "No parts found"; },
queryParams: function(p) {
return query;
},
columns: columns,
});
if (options.buttons) {

View File

@ -17,6 +17,10 @@ InvenTree | Search Results
<br><br>
<hr>
<div id='no-search-results'>
<h4><i>No results found</i></h4>
</div>
{% include "InvenTree/search_part_category.html" with collapse_id="categories" %}
{% include "InvenTree/search_parts.html" with collapse_id='parts' %}
@ -35,10 +39,12 @@ InvenTree | Search Results
{% block js_ready %}
{{ block.super }}
$(".panel-group").hide();
function onSearchResults(table, output) {
$(table).on('load-success.bs.table', function() {
var panel = $(output).parent('.panel-group');
var panel = $(output).closest('.panel-group');
var n = $(table).bootstrapTable('getData').length;
@ -48,8 +54,6 @@ InvenTree | Search Results
$(panel).hide();
$(table).hide();
} else {
text = n + ' result';
@ -59,6 +63,8 @@ InvenTree | Search Results
}
$(panel).show();
$("#no-search-results").hide();
}
$(output).html(text);
@ -120,6 +126,7 @@ InvenTree | Search Results
search: "{{ query }}",
},
allowInactive: true,
checkbox: false,
}
);

View File

@ -3,5 +3,5 @@
<div class="form-group">
<input type="text" name='search' class="form-control" placeholder="Search"{% if query_text %} value="{{ query }}"{% endif %}>
</div>
<button type="submit" id='search-submit' class="btn btn-default">Submit</button>
<button type="submit" id='search-submit' class="btn btn-default">Search</button>
</form>