Don't update count on tables without a summary row

The horizon.tabs javascript was updating the last row of any <table>
in the tab when the focus was changed to a different tab, stomping
over the last row of the table.

This commit limits updates to tables with the .datatable class,
and adds a class to the updated <span> in affected templates
so it can be selected a little more unambiguously.

Fixes bug #1080513.

Change-Id: I1b778bdc77887dcf540c96c2ab8be239bc13258c
This commit is contained in:
Kieran Spear 2013-01-14 14:35:18 +11:00
parent 158ce5ca26
commit 4632aa58ae
3 changed files with 10 additions and 8 deletions

View File

@ -18,7 +18,7 @@ horizon.datatables = {
// Trigger the update handlers.
$rows_to_update.each(function(index, row) {
var $row = $(this),
$table = $row.closest('table');
$table = $row.closest('table.datatable');
horizon.ajax.queue({
url: $row.attr('data-update-url'),
error: function (jqXHR, textStatus, errorThrown) {
@ -185,10 +185,10 @@ horizon.datatables.update_footer_count = function (el, modifier) {
// code paths for table or browser footers...
$browser = $el.closest("#browser_wrapper");
if ($browser.length) {
$footer = $($browser.find('.tfoot span')[1]);
$footer = $browser.find('.tfoot span.content_table_count');
}
else {
$footer = $el.find('tr:last span:first');
$footer = $el.find('table.datatable tfoot span.table_count');
}
row_count = $el.find('tbody tr:visible').length + modifier - $el.find('.empty').length;
footer_text_template = ngettext("Displaying %s item", "Displaying %s items", row_count);
@ -198,7 +198,7 @@ horizon.datatables.update_footer_count = function (el, modifier) {
horizon.datatables.set_table_sorting = function (parent) {
// Function to initialize the tablesorter plugin strictly on sortable columns.
$(parent).find("table.table").each(function () {
$(parent).find("table.datatable").each(function () {
var $table = $(this),
header_options = {};
// Disable if not sortable or has <= 1 item
@ -289,7 +289,7 @@ horizon.datatables.set_table_filter = function (parent) {
horizon.addInitFunction(function() {
horizon.datatables.validate_button();
horizon.datatables.update_footer_count($.find('table'),0);
horizon.datatables.update_footer_count($.find('table.datatable'),0);
// Bind the "select all" checkbox action.
$('div.table_wrapper, #modal_wrapper').on('click', 'table thead .multi_select_column :checkbox', function(evt) {
var $this = $(this),

View File

@ -34,7 +34,9 @@ horizon.addInitFunction(function () {
$(document).on("shown", ".nav-tabs a[data-toggle='tab']", function (evt) {
var $tab = $(evt.target),
$content = $($(evt.target).attr('data-target'));
horizon.datatables.update_footer_count($content.find("table"));
$content.find("table.datatable").each(function () {
horizon.datatables.update_footer_count($(this));
});
horizon.cookies.update("tabs", $tab.closest(".nav-tabs").attr("id"), $tab.attr('data-target'));
});

View File

@ -3,7 +3,7 @@
<div class="table_wrapper">
{% if needs_form_wrapper %}<form action="{{ table.get_absolute_url }}" method="POST">{% csrf_token %}{% endif %}
{% with columns=table.get_columns rows=table.get_rows %}
<table id="{{ table.name }}" class="table table-bordered table-striped">
<table id="{{ table.name }}" class="table table-bordered table-striped datatable">
<thead>
<tr class='table_caption'>
<th class='table_header' colspan='{{ columns|length }}'>
@ -50,7 +50,7 @@
{% endif %}
<tr>
<td colspan="{{ table.get_columns|length }}">
<span>{% blocktrans count counter=rows|length %}Displaying {{ counter }} item{% plural %}Displaying {{ counter }} items{% endblocktrans %}</span>
<span class="table_count">{% blocktrans count counter=rows|length %}Displaying {{ counter }} item{% plural %}Displaying {{ counter }} items{% endblocktrans %}</span>
{% if table.has_more_data %}
<span class="spacer">|</span>
<a href="?{{ table.get_pagination_string }}">More&nbsp;&raquo;</a>