Enhancing the RecordSet Class for Interactivity
Chapter 3 showed an enhancement to the RecordSet class that facilitated a user interface showing only one record at a time—a common way of displaying resultset data to the end user. The enhancement added the concept of a current record and provided methods to move to specific records (first, previous, next, last, and record number). To augment this functionality, let’s implement a feature to associate a field in a recordset with user interface controls and other elements (DataGlue style).
The Current Record Functionality
The current record functionality was described in Chapter 3, but we’ll add a few new methods to implement the gluing of components to individual RecordSet fields. The basic functionality that we will begin with is shown in Example 11-7.
// Initialize the current record number RecordSet.prototype.currentRecord = 0; // Return the current record RecordSet.prototype.getCurrentRecord = function ( ) { return this.getItemAt(this.currentRecord-1); }; // Return the current record number RecordSet.prototype.getCurrentRecordNum = function ( ) { return this.currentRecord }; RecordSet.prototype.move = function (direction) { switch (direction.toLowerCase( )) { case "first": this.currentRecord = 1; break; case "previous": if (--this.currentRecord < 1) this.currentRecord = 1; break; case "next": if (++this.currentRecord > this.getLength( )) this.currentRecord = this.getLength( ...Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access