/usr/share/javascript/yui3/datatable-base/datatable-base.js is in libjs-yui3-full 3.5.1-1ubuntu3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 | /*
YUI 3.5.1 (build 22)
Copyright 2012 Yahoo! Inc. All rights reserved.
Licensed under the BSD License.
http://yuilibrary.com/license/
*/
YUI.add('datatable-base', function(Y) {
/**
A Widget for displaying tabular data. The base implementation of DataTable
provides the ability to dynamically generate an HTML table from a set of column
configurations and row data.
Two classes are included in the `datatable-base` module: `Y.DataTable` and
`Y.DataTable.Base`.
@module datatable
@submodule datatable-base
@main datatable
@since 3.5.0
**/
// DataTable API docs included before DataTable.Base to make yuidoc work
/**
A Widget for displaying tabular data. Before feature modules are `use()`d,
this class is functionally equivalent to DataTable.Base. However, feature
modules can modify this class in non-destructive ways, expanding the API and
functionality.
This is the primary DataTable class. Out of the box, it provides the ability
to dynamically generate an HTML table from a set of column configurations and
row data. But feature module inclusion can add table sorting, pagintaion,
highlighting, selection, and more.
<pre><code>
// The functionality of this table would require additional modules be use()d,
// but the feature APIs are aggregated onto Y.DataTable.
// (Snippet is for illustration. Not all features are available today.)
var table = new Y.DataTable({
columns: [
{ type: 'checkbox', defaultChecked: true },
{ key: 'firstName', sortable: true, resizable: true },
{ key: 'lastName', sortable: true },
{ key: 'role', formatter: toRoleName }
],
data: {
source: 'http://myserver.com/service/json',
type: 'json',
schema: {
resultListLocator: 'results.users',
fields: [
'username',
'firstName',
'lastName',
{ key: 'role', type: 'number' }
]
}
},
recordType: UserModel,
pagedData: {
location: 'footer',
pageSizes: [20, 50, 'all'],
rowsPerPage: 20,
pageLinks: 5
},
editable: true
});
</code></pre>
### Column Configuration
The column configurations are set in the form of an array of objects, where
each object corresponds to a column. For columns populated directly from the
row data, a 'key' property is required to bind the column to that property or
attribute in the row data.
Not all columns need to relate to row data, nor do all properties or attributes
of the row data need to have a corresponding column. However, only those
columns included in the `columns` configuration attribute will be rendered.
Other column configuration properties are supported by the configured
`headerView`, `bodyView`, `footerView` classes as well as any features added by
plugins or class extensions. See the description of DataTable.HeaderView,
DataTable.BodyView, and other DataTable feature classes to see what column
properties they support.
Some examples of column configurations would be:
<pre><code>
// Basic
var columns = [{ key: 'firstName' }, { key: 'lastName' }, { key: 'age' }];
// For columns without any additional configuration, strings can be used
var columns = ['firstName', 'lastName', 'age'];
// Multi-row column headers (see DataTable.HeaderView for details)
var columns = [
{
label: 'Name',
children: [
{ key: 'firstName' },
{ key: 'lastName' }
]
},
'age' // mixing and matching objects and strings is ok
];
// Including columns that are not related 1:1 to row data fields/attributes
// (See DataTable.BodyView for details)
var columns = [
{
label: 'Name', // Needed for the column header
formatter: function (o) {
// Fill the column cells with data from firstName and lastName
if (o.data.age > 55) {
o.className += ' senior';
}
return o.data.lastName + ', ' + o.data.firstName;
}
},
'age'
];
// Columns that include feature configurations (for illustration; not all
// features are available today).
var columns = [
{ type: 'checkbox', defaultChecked: true },
{ key: 'firstName', sortable: true, resizable: true, min-width: '300px' },
{ key: 'lastName', sortable: true, resizable: true, min-width: '300px' },
{ key: 'age', emptyCellValue: '<em>unknown</em>' }
];
</code></pre>
### Row Data Configuration
The `data` configuration attribute is responsible for housing the data objects that will be rendered as rows. You can provide this information in two ways by default:
1. An array of simple objects with key:value pairs
2. A ModelList of Base-based class instances (presumably Model subclass
instances)
If an array of objects is passed, it will be translated into a ModelList filled
with instances of the class provided to the `recordType` attribute. This
attribute can also create a custom Model subclass from an array of field names
or an object of attribute configurations. If no `recordType` is provided, one
will be created for you from available information (see `_initRecordType`).
Providing either your own ModelList instance for `data`, or at least Model
class for `recordType`, is the best way to control client-server
synchronization when modifying data on the client side.
The ModelList instance that manages the table's data is available in the `data`
property on the DataTable instance.
### Rendering
Table rendering is a collaborative process between the DataTable and its
configured `headerView`, `bodyView`, and `footerView`. The DataTable renders
the `<table>` and `<caption>`, but the contents of the table are delegated to
instances of the classes provided to the `headerView`, `bodyView`, and
`footerView` attributes. If any of these attributes is unset, that portion of
the table won't be rendered.
DataTable.Base assigns the default `headerView` to `Y.DataTable.HeaderView` and
the default `bodyView` to `Y.DataTable.BodyView`, though either can be
overridden for custom rendering. No default `footerView` is assigned. See
those classes for more details about how they operate.
@class DataTable
@extends DataTable.Base
@since 3.5.0
**/
// DataTable API docs included before DataTable.Base to make yuidoc work
/**
The baseline implementation of a DataTable. This class should be used
primarily as a superclass for a custom DataTable with a specific set of
features. Because features can be composed onto `Y.DataTable`, custom
subclasses of DataTable.Base will remain unmodified when new feature modules
are loaded.
Example usage might look like this:
<pre><code>
// Custom subclass with only sorting and mutability added. If other datatable
// feature modules are loaded, this class will not be affected.
var MyTableClass = Y.Base.create('table', Y.DataTable.Base,
[ Y.DataTable.Sort, Y.DataTable.Mutable ]);
var table = new MyTableClass({
columns: ['firstName', 'lastName', 'age'],
data: [
{ firstName: 'Frank', lastName: 'Zappa', age: 71 },
{ firstName: 'Frank', lastName: 'Lloyd Wright', age: 144 },
{ firstName: 'Albert', lastName: 'Einstein', age: 132 },
...
]
});
table.render('#over-there');
// DataTable.Base can be instantiated if a featureless table is needed.
var table = new Y.DataTable.Base({
columns: ['firstName', 'lastName', 'age'],
data: [
{ firstName: 'Frank', lastName: 'Zappa', age: 71 },
{ firstName: 'Frank', lastName: 'Lloyd Wright', age: 144 },
{ firstName: 'Albert', lastName: 'Einstein', age: 132 },
...
]
});
table.render('#in-here');
</code></pre>
DataTable.Base is built from DataTable.Core, and sets the default `headerView`
to `Y.DataTable.HeaderView` and default `bodyView` to `Y.DataTable.BodyView`.
@class Base
@extends Widget
@uses DataTable.Core
@namespace DataTable
@since 3.5.0
**/
Y.DataTable.Base = Y.Base.create('datatable', Y.Widget, [Y.DataTable.Core],
null, {
ATTRS: {
// Default head and body views
headerView: { value: Y.DataTable.HeaderView },
bodyView : { value: Y.DataTable.BodyView }
}
});
// The DataTable API docs are above DataTable.Base docs.
Y.DataTable = Y.mix(
Y.Base.create('datatable', Y.DataTable.Base, []), // Create the class
Y.DataTable); // Migrate static and namespaced classes
}, '3.5.1' ,{requires:['datatable-core', 'base-build', 'widget', 'datatable-head', 'datatable-body']});
|