|
|
@ -28,14 +28,24 @@ $.fn.longtable = function(fields, options, data) { |
|
|
|
} |
|
|
|
else { |
|
|
|
el = $("<td></td>"); |
|
|
|
if (fields[field].fmt) { // Special formatting?
|
|
|
|
if (fields[field].fmt) { |
|
|
|
// Apply ad-hoc formatting.
|
|
|
|
el.html(fields[field].fmt(data[id])); |
|
|
|
} |
|
|
|
else { |
|
|
|
el.html(data[id][field]); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (fields[field].handle_longwords) { |
|
|
|
el.css("word-break", "break-all"); |
|
|
|
} |
|
|
|
|
|
|
|
if (fields[field].max_width) { |
|
|
|
el.css("max-width", fields[field].max_width); |
|
|
|
} |
|
|
|
el.css("width", fields[field].width); |
|
|
|
|
|
|
|
return el; |
|
|
|
}, |
|
|
|
_gen_tr: function(id) { |
|
|
@ -61,7 +71,6 @@ $.fn.longtable = function(fields, options, data) { |
|
|
|
$(elem).trigger("new-row", [data[id], el]); |
|
|
|
shown_rows[id] = true; |
|
|
|
}, |
|
|
|
|
|
|
|
_sort_by: function(field) { |
|
|
|
if (field !== undefined) { |
|
|
|
if (sorted_by == field) { |
|
|
@ -74,22 +83,18 @@ $.fn.longtable = function(fields, options, data) { |
|
|
|
} |
|
|
|
lt.sort_by(sorted_by, sorted_reverse); |
|
|
|
}, |
|
|
|
|
|
|
|
_apply_filter: function() { |
|
|
|
data = data.filter(filter); |
|
|
|
}, |
|
|
|
_reset_data: function() { |
|
|
|
data = orig_data; |
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
set_filter: function(f) { |
|
|
|
filter = f; |
|
|
|
lt._reset_data(); |
|
|
|
lt._apply_filter(); |
|
|
|
lt._sort_by(); |
|
|
|
}, |
|
|
|
|
|
|
|
sort_by: function(field, reverse) { |
|
|
|
if (field !== undefined) { |
|
|
|
sorted_by = field; |
|
|
@ -103,7 +108,6 @@ $.fn.longtable = function(fields, options, data) { |
|
|
|
|
|
|
|
lt.update_data(); |
|
|
|
}, |
|
|
|
|
|
|
|
update_viewport: function() { |
|
|
|
var first = $(window).scrollTop() - $(elem).offset().top - options.row_h; |
|
|
|
var last = first + $(window).height(); |
|
|
@ -111,11 +115,12 @@ $.fn.longtable = function(fields, options, data) { |
|
|
|
first = Math.floor(first / options.row_h); |
|
|
|
last = Math.ceil (last / options.row_h); |
|
|
|
|
|
|
|
first = first < 0 ? 0 : first; |
|
|
|
first = first < 1 ? 1 : first; |
|
|
|
last = last >= data.length ? data.length - 1 : last; |
|
|
|
|
|
|
|
$.each(shown_rows, function(id) { |
|
|
|
if (id < first || id > last) { |
|
|
|
// Remove only the rows after.
|
|
|
|
if (id > last) { |
|
|
|
lt._remove(id); |
|
|
|
} |
|
|
|
}); |
|
|
@ -124,20 +129,14 @@ $.fn.longtable = function(fields, options, data) { |
|
|
|
if (!shown_rows[id]) lt._insert(id); |
|
|
|
} |
|
|
|
}, |
|
|
|
|
|
|
|
update_data: function() { |
|
|
|
|
|
|
|
lt._clean(); |
|
|
|
lt.update_viewport(); |
|
|
|
}, |
|
|
|
|
|
|
|
get_data: function() { |
|
|
|
return data; |
|
|
|
}, |
|
|
|
|
|
|
|
destroy: function() { |
|
|
|
}, |
|
|
|
|
|
|
|
destroy: function() {}, |
|
|
|
// http://web.archive.org/web/20130826203933/http://my.opera.com/GreyWyvern/blog/show.dml/1671288
|
|
|
|
sort_alphanum: function(a, b) { |
|
|
|
function chunkify(t) { |
|
|
@ -170,8 +169,6 @@ $.fn.longtable = function(fields, options, data) { |
|
|
|
// End of foreign code
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
lt._gen_tr().appendTo(elem); |
|
|
|
lt.update_data(); |
|
|
|
|
|
|
|