Author: abelevich
Date: 2010-01-11 08:35:55 -0500 (Mon, 11 Jan 2010)
New Revision: 16253
Modified:
root/ui-sandbox/trunk/components/tables/ui/src/main/resources/META-INF/resources/datatable.js
Log:
base dataTable js api
Modified:
root/ui-sandbox/trunk/components/tables/ui/src/main/resources/META-INF/resources/datatable.js
===================================================================
---
root/ui-sandbox/trunk/components/tables/ui/src/main/resources/META-INF/resources/datatable.js 2010-01-11
13:35:00 UTC (rev 16252)
+++
root/ui-sandbox/trunk/components/tables/ui/src/main/resources/META-INF/resources/datatable.js 2010-01-11
13:35:55 UTC (rev 16253)
@@ -1 +1,119 @@
-var c = 1;
\ No newline at end of file
+(function (jQuery, richfaces) {
+
+ richfaces.ui = richfaces.ui || {};
+
+ richfaces.ui.DataTable = function(id, options) {
+ this.id = id;
+ this.options = options;
+ this.sortMode = options.sortMode;
+ this.initializeColumns(options.columns);
+ };
+
+ jQuery.extend(richfaces.ui.DataTable.prototype, ( function () {
+
+ var columns = {};
+
+ var convertId = function (id){
+ return id.replace(/:/g, "\\:");
+ };
+
+ var getElement = function (id) {
+ return $("#" + convertId(id));
+ };
+
+ return {
+
+ initializeColumns : function(options) {
+ for(var property in options) {
+ var column = new richfaces.ui.Column(property,
options[property]);
+ if(column.sortable) {
+ var element = getElement(column.id);
+ var _this = this;
+
+ element.bind(column.sortEvent, column, function(e) {
+ _this.processSortEvent(e);
+ });
+ }
+ columns[property] = column;
+ }
+ },
+
+ processSortEvent: function (e) {
+ var column = e.data;
+ column.toggleSortControl(e);
+
+ if(this.sortMode == 'single') {
+ for(var x in columns) {
+ if(columns[x].id != column.id) {
+ columns[x].resetSortControl();
+ }
+ }
+ }
+ }
+ }
+
+ })());
+
+})(jQuery, window.RichFaces);
+
+
+(function (jQuery, richfaces) {
+
+ richfaces.ui = richfaces.ui || {};
+
+ richfaces.ui.Column = function(id, options) {
+ this.id = id;
+ this.sortable = options.sorting.sortable;
+ this.sortOrder = options.sorting.sortOrder;
+ this.sortEvent = options.sorting.sortEvent;
+ this.initializeControls(id);
+ };
+
+ jQuery.extend(richfaces.ui.Column.prototype, ( function () {
+
+ var convertId = function (id){
+ return id.replace(/:/g, "\\:");
+ };
+
+ var getElement = function (id) {
+ return $("#" + convertId(id));
+ };
+
+ return {
+ initializeControls: function(id) {
+ this.asc = getElement(id+':ASCENDING');
+ this.desc = getElement(id+':DESCENDING');
+ this.unsort = getElement(id+':UNSORTED');
+ },
+
+ toggleSortControl: function(e) {
+
+ if(this.sortOrder == "ASCENDING") {
+ this.asc.hide();
+ this.unsort.hide();
+ this.desc.show();
+ this.sortOrder = "DESCENDING";
+
+ } else if(this.sortOrder == "DESCENDING") {
+ this.asc.show();
+ this.unsort.hide();
+ this.desc.hide();
+ this.sortOrder = "ASCENDING";
+
+ } else if(this.sortOrder == "UNSORTED") {
+ this.asc.hide();
+ this.unsort.hide();
+ this.desc.show();
+ this.sortOrder = "DESCENDING";
+ }
+ },
+
+ resetSortControl: function(){
+ this.asc.hide();
+ this.desc.hide();
+ this.unsort.show();
+ }
+ }
+ })());
+
+})(jQuery, window.RichFaces);