JQuery_ Novice to Ninja - Earle Castledine [130]
var reveal = function (current) {
$back.removeClass("paging-disabled");
$next.removeClass("paging-disabled");
$rows
.hide()
.slice(current * pageLength, current * pageLength + pageLength)
.show();
$nav.find("a.paging-this b").text(current + 1);
}
reveal starts by clearing the disabled classes, so that our buttons avoid becoming stranded in a disabled state. We then use the slice method again to select the correct rows to display.
Note: Nested Functions
The structure we’ve used here is a little odd—but when you think about it, it’s straightforward: we’ve nested a function declaration inside another function. All this does is restrict the scope of the function (see the section called “Scope” in Chapter 6), so it can only be called from within its parent function. Why is this a good idea? In this case our function has no purpose outside its parent, and placing it in a wider scope would only put it at greater risk of conflicting with other function or variable names.
Editing a Row
We’ve already handled inline editing on a single element, but what if you want to make an entire table editable? We’ll add editing functionality to the data grid by inserting an Edit button at the end of each row, turning that entire row of cells into input elements, as shown in Figure 8.8.
Figure 8.8. Editable rows in action
The cells that contain your tabular data provide an excellent opportunity to store information as we manipulate the markup; this is actually a trick we used in our form controls. What we’ve yet to experience, though, is a row element to group our work area. Let’s see how to use it:
chapter_08/09_editable_table_cells/index.html (excerpt)