Show record count in list header

This commit is contained in:
Faris Ansari 2017-10-23 20:10:15 +05:30
parent 1fbc8ff448
commit bc45beb868
3 changed files with 43 additions and 0 deletions

View file

@ -578,3 +578,13 @@ def get_list(doctype, *args, **kwargs):
'''wrapper for DatabaseQuery'''
kwargs.pop('cmd', None)
return DatabaseQuery(doctype).execute(None, *args, **kwargs)
@frappe.whitelist()
def get_count(doctype, filters=None):
if filters:
filters = json.loads(filters)
if isinstance(filters, list):
filters = frappe.utils.make_filter_dict(filters)
return frappe.db.count(doctype, filters=filters)

View file

@ -355,6 +355,29 @@ frappe.views.ListRenderer = Class.extend({
this.render_tags($item_container, value);
});
this.render_count(values.length);
},
render_count: function(current_count) {
console.log(this)
const $header_right = this.list_view.list_header.find('.list-item__content--activity');
frappe.call({
method: 'frappe.model.db_query.get_count',
args: {
doctype: this.doctype,
filters: this.list_view.get_filters_args()
}
}).then(r => {
const count = r.message;
const $html = $(`<span>${current_count} of ${count}</span>`);
$html.css({
marginRight: '10px'
})
$header_right.addClass('text-muted');
$header_right.html($html);
})
},
// returns html for a data item,

View file

@ -781,6 +781,16 @@ def make_filter_tuple(doctype, key, value):
else:
return [doctype, key, "=", value]
def make_filter_dict(filters):
'''convert this [[doctype, key, operator, value], ..]
to this { key: (operator, value), .. }
'''
_filter = frappe._dict()
for f in filters:
_filter[f[1]] = (f[2], f[3])
return _filter
def scrub_urls(html):
html = expand_relative_urls(html)
# encoding should be responsibility of the composer