소스 검색

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 () {
 		priv.init = function () {
 			_cont = priv.options.id;
 			_cont = priv.options.id;
+			priv.initEvents();
 			priv.options.types.string = ((priv.options.types || {}).string || {});
 			priv.options.types.string = ((priv.options.types || {}).string || {});
 			priv.options.types.number = ((priv.options.types || {}).number || {});
 			priv.options.types.number = ((priv.options.types || {}).number || {});
 			priv.options.types.bool = ((priv.options.types || {}).bool || {});
 			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.
 		 creates the table with all its parts and handlers.
 		 note that only the parts we need is created.
 		 note that only the parts we need is created.
 		 (yeah, the function is huge)
 		 (yeah, the function is huge)
 		 */
 		 */
-		priv.createTable = function () {
+		priv.renderTable = function () {
 			//create table itself
 			//create table itself
 			if (!_table) {
 			if (!_table) {
 				_head = _body = _foot = undefined;
 				_head = _body = _foot = undefined;
@@ -626,10 +645,6 @@ class TableAjax extends ViewAjax {
 				_head = $('<thead></thead>').prependTo(_table);
 				_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
 			//sort the columns in index order
 			var colsSorted = Object.keys(_data.cols).sort(function (a, b) {
 			var colsSorted = Object.keys(_data.cols).sort(function (a, b) {
 				return _data.cols[a].index - _data.cols[b].index;
 				return _data.cols[a].index - _data.cols[b].index;
@@ -1237,7 +1252,7 @@ class TableAjax extends ViewAjax {
 					div.on('click', 'input', priv.columnPickerClicked);
 					div.on('click', 'input', priv.columnPickerClicked);
 				}
 				}
 
 
-				if (priv.options.rowFunctions) {
+				if (priv.options.tblFunctions) {
 					$.map(priv.options.tblFunctions, function(funObj, funName){
 					$.map(priv.options.tblFunctions, function(funObj, funName){
 						var div = $('<div class="btn-group"></div>').appendTo(footToolbar);
 						var div = $('<div class="btn-group"></div>').appendTo(footToolbar);
 						var funHtml = $('<button class="btn btn-sm btn-default"></button>');
 						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);
 						$('<input {0} type="checkbox" >&nbsp;Filter</input>'.f(priv.options.filter ? 'checked' : '')).appendTo(li);
 						li.on('click', 'input', function (e) {
 						li.on('click', 'input', function (e) {
 							priv.options.filter = !priv.options.filter;
 							priv.options.filter = !priv.options.filter;
-							_head = undefined;
-							priv.createTable();
+							jQuery(_cont).trigger('TableAjax:render', ['head']);
 						});
 						});
 					}
 					}
 					if (priv.options.actions.columnPicker) {
 					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);
 						$('<input {0} type="checkbox" >&nbsp;ColumnPicker</input>'.f(priv.options.columnPicker ? 'checked' : '')).appendTo(li);
 						li.on('click', 'input', function (e) {
 						li.on('click', 'input', function (e) {
 							priv.options.columnPicker = !priv.options.columnPicker;
 							priv.options.columnPicker = !priv.options.columnPicker;
-							_foot = undefined;
-							priv.createTable();
+							jQuery(_cont).trigger('TableAjax:render', ['foot']);
 						});
 						});
 					}
 					}
 					if (priv.options.actions.custom) {
 					if (priv.options.actions.custom) {
@@ -1700,9 +1713,7 @@ class TableAjax extends ViewAjax {
 			if (!skipCols) {
 			if (!skipCols) {
 				_head = undefined;
 				_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();
 			priv.saveHiddenCols();
 
 
 			//_data.cols[column].index = new priv.ext.XDate();
 			//_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) {
 		priv.columnHideClicked = function (e) {
@@ -2222,10 +2227,7 @@ class TableAjax extends ViewAjax {
 			priv.saveHiddenCols();
 			priv.saveHiddenCols();
 
 
 			//_data.cols[column].index = new priv.ext.XDate();
 			//_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);
 						priv.setData(data.d, skipCols, resetChecked);
 					else
 					else
 						priv.setData(data, skipCols, resetChecked);
 						priv.setData(data, skipCols, resetChecked);
-					if (typeof callback == "function")
-						callback.call(this);
 					_table.parent().parent().removeClass('AjaxTable-loading');
 					_table.parent().parent().removeClass('AjaxTable-loading');
 				},
 				},
 				error: function (err) {
 				error: function (err) {