Skip to content

Commit fbf2e73

Browse files
committed
added toolbar_message(): same as footer_message(), but appends message to toolbar
1 parent 4ae831a commit fbf2e73

File tree

4 files changed

+33
-1
lines changed

4 files changed

+33
-1
lines changed

CHANGELOG.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ History
66
v4.4.3
77
------
88
* assign '__iexact', instead of '__icontains', as default 'lookup_field' value for columns with choices
9+
* added toolbar_message(): same as footer_message(), but appends message to toolbar
910

1011
v4.4.2
1112
------

README.rst

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,7 @@ Example::
407407
'autofilter': False, # see `Filtering single columns` below
408408
'boolean': False, # treat calculated column as BooleanField
409409
'max_length': 0, # if > 0, clip result longer then max_length
410-
'lookup_field': '__icontains', # used for searches; default: '__icontains'
410+
'lookup_field': '__icontains', # used for searches; default: '__iexact' for columns with choices, '__icontains' in all other cases
411411
}, {
412412
...
413413

@@ -868,6 +868,15 @@ Example:
868868

869869
.. image:: screenshots/005.png
870870

871+
toolbar_message()
872+
.................
873+
874+
Same as footer_message() but appends message to toolbar:
875+
876+
.. code:: python
877+
878+
def footer_message(self, qs, params):
879+
return 'Selected rows: %d' % qs.count()
871880
872881
render_clip_value_as_html()
873882
...........................

ajax_datatable/static/ajax_datatable/js/utils.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,17 @@ window.AjaxDatatableViewUtils = (function() {
362362
footer.html(html);
363363
}
364364

365+
function _write_toolbar_message(table, html) {
366+
var wrapper = table.closest('.dataTables_wrapper');
367+
var toolbar = wrapper.find('.toolbar');
368+
var toolbar_message = toolbar.find('.dataTables_extraToolbar');
369+
if (toolbar_message.length <= 0) {
370+
$('<div class="dataTables_extraToolbar"></div>').appendTo(toolbar);
371+
toolbar_message = toolbar.find('.dataTables_extraToolbar');
372+
}
373+
toolbar_message.html(html);
374+
}
375+
365376
function initialize_table(element, url, extra_options={}, extra_data={}) {
366377

367378
var data = {action: 'initialize'};
@@ -441,6 +452,10 @@ window.AjaxDatatableViewUtils = (function() {
441452
if (footer_message !== null) {
442453
_write_footer(table, footer_message);
443454
}
455+
var toolbar_message = data.toolbar_message;
456+
if (toolbar_message !== null) {
457+
_write_toolbar_message(table, toolbar_message);
458+
}
444459

445460
}).fail(function(jqXHR, textStatus, errorThrown) {
446461
console.log('ERROR: ' + jqXHR.responseText);

ajax_datatable/views.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -562,6 +562,7 @@ def get(self, request, *args, **kwargs):
562562
paginator = Paginator(qs, params['length'])
563563
response_dict = self.get_response_dict(request, paginator, params['draw'], params['start'])
564564
response_dict['footer_message'] = self.footer_message(qs, params)
565+
response_dict['toolbar_message'] = self.toolbar_message(qs, params)
565566

566567
# Prepare response
567568
response = HttpResponse(
@@ -950,6 +951,12 @@ def footer_message(self, qs, params):
950951
# return 'Selected rows: %d' % qs.count()
951952
return None
952953

954+
def toolbar_message(self, qs, params):
955+
"""
956+
Overriden to append a message to the bottom of the table
957+
"""
958+
return None
959+
953960
def list_autofilter_choices(self, request, column_spec, field, initial_search_value):
954961
"""
955962
Collects distinct values from specified field,

0 commit comments

Comments
 (0)