Преглед на файлове

TableAjax use events for render table

Piotr Labudda преди 10 години
родител
ревизия
66c662a6ab
променени са 1 файла, в които са добавени 28 реда и са изтрити 28 реда
  1. 28 28
      SE/se-lib/TableAjax.php

+ 28 - 28
SE/se-lib/TableAjax.php

@@ -575,6 +575,7 @@ class TableAjax extends ViewAjax {
 		 */
 		priv.init = function () {
 			_cont = priv.options.id;
+			priv.initEvents();
 			priv.options.types.string = ((priv.options.types || {}).string || {});
 			priv.options.types.number = ((priv.options.types || {}).number || {});
 			priv.options.types.bool = ((priv.options.types || {}).bool || {});
@@ -607,12 +608,30 @@ class TableAjax extends ViewAjax {
 			}
 		};
 
+		priv.initEvents = function () {
+			jQuery(_cont).on('TableAjax:render', priv.onRender);
+		};
+
+		priv.onRender = function(e) {
+			if (priv.options.debug) console.log('onRender.arguments:', arguments.length, arguments, 'e:', e);
+			if (arguments.length > 1) {
+				for (var i=1; i<arguments.length; i++) {
+					switch (arguments[i]) {
+						case 'head': _head = undefined; break;
+						case 'body': _body = undefined; break;
+						case 'foot': _foot = undefined; break;
+					}
+				}
+				priv.renderTable();
+			}
+		};
+
 		/*
 		 creates the table with all its parts and handlers.
 		 note that only the parts we need is created.
 		 (yeah, the function is huge)
 		 */
-		priv.createTable = function () {
+		priv.renderTable = function () {
 			//create table itself
 			if (!_table) {
 				_head = _body = _foot = undefined;
@@ -626,10 +645,6 @@ class TableAjax extends ViewAjax {
 				_head = $('<thead></thead>').prependTo(_table);
 			}
 
-			// TODO: test colgroup
-			//_table.find('colgroup').remove();
-			//$('<colgroup><col span="1" style="background-color:red"><col span="10" style="width:200px;overlow-x:auto"></colgroup>').prependTo(_table);
-
 			//sort the columns in index order
 			var colsSorted = Object.keys(_data.cols).sort(function (a, b) {
 				return _data.cols[a].index - _data.cols[b].index;
@@ -1237,7 +1252,7 @@ class TableAjax extends ViewAjax {
 					div.on('click', 'input', priv.columnPickerClicked);
 				}
 
-				if (priv.options.rowFunctions) {
+				if (priv.options.tblFunctions) {
 					$.map(priv.options.tblFunctions, function(funObj, funName){
 						var div = $('<div class="btn-group"></div>').appendTo(footToolbar);
 						var funHtml = $('<button class="btn btn-sm btn-default"></button>');
@@ -1266,8 +1281,7 @@ class TableAjax extends ViewAjax {
 						$('<input {0} type="checkbox" >&nbsp;Filter</input>'.f(priv.options.filter ? 'checked' : '')).appendTo(li);
 						li.on('click', 'input', function (e) {
 							priv.options.filter = !priv.options.filter;
-							_head = undefined;
-							priv.createTable();
+							jQuery(_cont).trigger('TableAjax:render', ['head']);
 						});
 					}
 					if (priv.options.actions.columnPicker) {
@@ -1275,8 +1289,7 @@ class TableAjax extends ViewAjax {
 						$('<input {0} type="checkbox" >&nbsp;ColumnPicker</input>'.f(priv.options.columnPicker ? 'checked' : '')).appendTo(li);
 						li.on('click', 'input', function (e) {
 							priv.options.columnPicker = !priv.options.columnPicker;
-							_foot = undefined;
-							priv.createTable();
+							jQuery(_cont).trigger('TableAjax:render', ['foot']);
 						});
 					}
 					if (priv.options.actions.custom) {
@@ -1700,9 +1713,7 @@ class TableAjax extends ViewAjax {
 			if (!skipCols) {
 				_head = undefined;
 			}
-			_body = undefined;
-			_foot = undefined;
-			priv.createTable();
+			jQuery(_cont).trigger('TableAjax:render', ['body', 'foot']);
 		};
 
 		/**
@@ -2095,9 +2106,7 @@ class TableAjax extends ViewAjax {
 				});
 			}
 
-			_body = undefined;
-			_foot = undefined;
-			priv.createTable();
+			jQuery(_cont).trigger('TableAjax:render', ['body', 'foot']);
 		};
 
 		/*
@@ -2127,9 +2136,7 @@ class TableAjax extends ViewAjax {
 				});
 			}
 
-			_body = undefined;
-			_foot = undefined;
-			priv.createTable();
+			jQuery(_cont).trigger('TableAjax:render', ['body', 'foot']);
 		};
 
 		/*
@@ -2201,9 +2208,7 @@ class TableAjax extends ViewAjax {
 			priv.saveHiddenCols();
 
 			//_data.cols[column].index = new priv.ext.XDate();
-			_head = undefined;
-			_body = undefined;
-			priv.createTable();
+			jQuery(_cont).trigger('TableAjax:render', ['head', 'body']);
 		};
 
 		priv.columnHideClicked = function (e) {
@@ -2222,10 +2227,7 @@ class TableAjax extends ViewAjax {
 			priv.saveHiddenCols();
 
 			//_data.cols[column].index = new priv.ext.XDate();
-			_head = undefined;
-			_body = undefined;
-			_foot = undefined;
-			priv.createTable();
+			jQuery(_cont).trigger('TableAjax:render', ['head', 'body', 'foot']);
 		};
 
 		/*
@@ -2484,8 +2486,6 @@ class TableAjax extends ViewAjax {
 						priv.setData(data.d, skipCols, resetChecked);
 					else
 						priv.setData(data, skipCols, resetChecked);
-					if (typeof callback == "function")
-						callback.call(this);
 					_table.parent().parent().removeClass('AjaxTable-loading');
 				},
 				error: function (err) {