Skip to content

Commit 3648b51

Browse files
committed
Grid SPF: Improve pager control, better integrate in menugrid demo. Show current/total rows.
1 parent a6fbcbb commit 3648b51

File tree

3 files changed

+38
-17
lines changed

3 files changed

+38
-17
lines changed

grid-spf/datasource.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ $.widget( "ui.datasource", {
6565
var that = this;
6666
this.options.source( request, function( data, totalCount ) {
6767
that.data = data;
68-
that.totalCount = totalCount;
68+
that.totalCount = parseInt(totalCount, 10);
6969
that._trigger( "response" );
7070
});
7171
return this;

grid-spf/menugrid.html

Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,18 @@
2424
resource: "http://odata.netflix.com/Catalog/Titles"
2525
});
2626
var grid = $( "#movies" ).grid({
27-
source: movies
27+
source: movies,
28+
refresh: function() {
29+
var paging = movies.options.paging,
30+
total = movies.totalCount;
31+
$(".paging-from").text( paging.offset + 1 );
32+
var to = paging.offset + paging.limit + 1;
33+
if (to > total) {
34+
to = total;
35+
}
36+
$(".paging-to").text( to );
37+
$(".paging-total").text( total );
38+
}
2839
}).menugrid();
2940

3041
$( "#pager" ).pager({
@@ -38,6 +49,9 @@
3849
.ui-menu {
3950
position: absolute;
4051
}
52+
tfoot td {
53+
text-align: center;
54+
}
4155
</style>
4256
</head>
4357
<body>
@@ -64,20 +78,21 @@ <h2>Movies! Click header for sort menu, use inputs for filtering, pager for pagi
6478
</thead>
6579
<tbody>
6680
</tbody>
81+
<tfoot>
82+
<tr>
83+
<td id="pager" colspan="2" class="ui-state-default">
84+
<button data-page="first">First</button>
85+
<button data-page="prev">Prev</button>
86+
<span>
87+
Page <input class="current" size="4"/> of <span class="total">0</span>
88+
</span>
89+
<button data-page="next">Next</button>
90+
<button data-page="last">Last</button>
91+
</td>
92+
<td class="ui-state-default">Viewing rows <span class="paging-from">0</span> to <span class="paging-to">0</span> of <span class="paging-total">0</span>
93+
</tr>
94+
</tfoot>
6795
</table>
6896

69-
<p id="pager">
70-
<button data-page="first">First</button>
71-
<button data-page="prev">Prev</button>
72-
<button data-page="prevStep">-1</button>
73-
<span>
74-
Page <input class="current" size="4"/>/<span class="total">0</span>,
75-
Total records <span class="totalRecords">0</span>
76-
</span>
77-
<button data-page="nextStep">+1</button>
78-
<button data-page="next">Next</button>
79-
<button data-page="last">Last</button>
80-
</p>
81-
8297
</body>
8398
</html>

grid-spf/pager.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@ $.widget( "spf.pager", {
1616
that.options.source.refresh();
1717
}).buttonset().find("button");
1818

19+
// TODO refactor
20+
this.buttons.filter('[data-page="first"]').button("option", "icons.primary", "ui-icon-seek-first");
21+
this.buttons.filter('[data-page="prev"]').button("option", "icons.primary", "ui-icon-seek-prev");
22+
this.buttons.filter('[data-page="next"]').button("option", "icons.secondary", "ui-icon-seek-next");
23+
this.buttons.filter('[data-page="last"]').button("option", "icons.secondary", "ui-icon-seek-end");
24+
1925
this.element.find(".current").change(function() {
2026
that.page( +$(this).val() );
2127
that.options.source.refresh();
@@ -26,10 +32,10 @@ $.widget( "spf.pager", {
2632

2733
var source = this.options.source;
2834
if (!source.options.paging.offset) {
29-
this.buttons.slice(0, 3).button("disable")
35+
this.buttons.filter('[data-page="first"], [data-page="prev"], [data-page="prevStep"]').button("disable");
3036
}
3137
if (source.options.paging.offset + source.options.paging.limit >= source.totalCount) {
32-
this.buttons.slice(3, 6).button("disable")
38+
this.buttons.filter('[data-page="last"], [data-page="next"], [data-page="nextStep"]').button("disable");
3339
}
3440
this.element.find(".current").val(this.page());
3541
this.element.find(".total").text(this.totalPages());

0 commit comments

Comments
 (0)