| 1 |
<!DOCTYPE html> |
| 2 |
<html> |
| 3 |
<head> |
| 4 |
<title>Stupid jQuery table sort</title> |
| 5 |
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script> |
| 6 |
<script src="../stupidtable.js?dev"></script> |
| 7 |
<script> |
| 8 |
// ====================================================== |
| 9 |
// Example 1 |
| 10 |
// ====================================================== |
| 11 |
$(function(){ |
| 12 |
var $table = $("#example-1"); |
| 13 |
$table.stupidtable_settings({ |
| 14 |
should_redraw: function(sort_info){ |
| 15 |
var sorted_column = sort_info.column; |
| 16 |
var first_val = sorted_column[0]; |
| 17 |
var last_val = sorted_column[sorted_column.length - 1][0]; |
| 18 |
|
| 19 |
// If first and last element of the sorted column are the same, we |
| 20 |
// can assume all elements are the same. |
| 21 |
return sort_info.compare_fn(first_val, last_val) !== 0; |
| 22 |
} |
| 23 |
}); |
| 24 |
$table.stupidtable(); |
| 25 |
}); |
| 26 |
|
| 27 |
</script> |
| 28 |
<style type="text/css"> |
| 29 |
table { |
| 30 |
border-collapse: collapse; |
| 31 |
} |
| 32 |
th, td { |
| 33 |
padding: 5px 10px; |
| 34 |
border: 1px solid #999; |
| 35 |
} |
| 36 |
th { |
| 37 |
background-color: #eee; |
| 38 |
} |
| 39 |
th[data-sort]{ |
| 40 |
cursor:pointer; |
| 41 |
} |
| 42 |
tr.awesome{ |
| 43 |
color: red; |
| 44 |
} |
| 45 |
</style> |
| 46 |
</style> |
| 47 |
</head> |
| 48 |
|
| 49 |
<body> |
| 50 |
|
| 51 |
<h1>StupidTable with settings</h1> |
| 52 |
|
| 53 |
<p>This page shows how specific behaviors can be introduced by providing |
| 54 |
settings to StupidTable. View the source of this page to see the settings in |
| 55 |
use.</p> |
| 56 |
|
| 57 |
<hr/> |
| 58 |
|
| 59 |
<h2>Example 1</h2> |
| 60 |
|
| 61 |
<p> This table does not redraw when attempting to sort a column that has identical values in all rows. </p> |
| 62 |
|
| 63 |
<table id='example-1'> |
| 64 |
<thead> |
| 65 |
<tr> |
| 66 |
<th data-sort="int">int</th> |
| 67 |
<th data-sort="float">float</th> |
| 68 |
<th data-sort="string" data-sort-onload="yes">string</th> |
| 69 |
<th data-sort="int">int (identical)</th> |
| 70 |
</tr> |
| 71 |
</thead> |
| 72 |
<tbody> |
| 73 |
<tr> |
| 74 |
<td>15</td> |
| 75 |
<td>-.18</td> |
| 76 |
<td>banana</td> |
| 77 |
<td>99</td> |
| 78 |
</tr> |
| 79 |
<tr class="awesome"> |
| 80 |
<td>95</td> |
| 81 |
<td>36</td> |
| 82 |
<td>coke</td> |
| 83 |
<td>99</td> |
| 84 |
</tr> |
| 85 |
<tr> |
| 86 |
<td>2</td> |
| 87 |
<td>-152.5</td> |
| 88 |
<td>apple</td> |
| 89 |
<td>99</td> |
| 90 |
</tr> |
| 91 |
<tr> |
| 92 |
<td>-53</td> |
| 93 |
<td>88.5</td> |
| 94 |
<td>zebra</td> |
| 95 |
<td>99</td> |
| 96 |
</tr> |
| 97 |
<tr> |
| 98 |
<td>195</td> |
| 99 |
<td>-858</td> |
| 100 |
<td>orange</td> |
| 101 |
<td>99</td> |
| 102 |
</tr> |
| 103 |
</tbody> |
| 104 |
</table> |
| 105 |
|
| 106 |
<pre><code> |
| 107 |
var $table = $("#example-1"); |
| 108 |
$table.stupidtable_settings({ |
| 109 |
should_redraw: function(sort_info){ |
| 110 |
var sorted_column = sort_info.column; |
| 111 |
var first_val = sorted_column[0]; |
| 112 |
var last_val = sorted_column[sorted_column.length - 1][0]; |
| 113 |
|
| 114 |
// If first and last element of the sorted column are the same, we |
| 115 |
// can assume all elements are the same. |
| 116 |
return sort_info.compare_fn(first_val, last_val) !== 0; |
| 117 |
} |
| 118 |
}); |
| 119 |
$table.stupidtable(); |
| 120 |
</code></pre> |
| 121 |
|
| 122 |
</body> |
| 123 |
</html> |