Ver Fonte

updated UI::table when empty data, added empty_msg param

Piotr Labudda há 9 anos atrás
pai
commit
3406a9224f
1 ficheiros alterados com 26 adições e 18 exclusões
  1. 26 18
      SE/se-lib/UI.php

+ 26 - 18
SE/se-lib/UI.php

@@ -133,28 +133,36 @@ class UI {
 		if ($html_id) $tableAttrs['id'] = $html_id;
 		self::startTag('table', $tableAttrs); echo "\n";
 		if ($caption) { self::tag('caption', null, $caption); echo "\n"; }
-		self::startTag('thead', null); echo "\n";
-		self::startTag('tr', null); echo "\n";
-		if ($showLp) { self::tag('th', [ 'style' => "padding:2px" ], "Lp.");  echo "\n"; }
-		foreach ($cols as $colName) {
-			if (in_array($colName, $hiddenCols)) continue;
-			self::tag('th', [ 'style' => "padding:2px"], $colName); echo "\n";
-		}
-		self::endTag('tr'); echo "\n";
-		self::endTag('thead'); echo "\n";
-		self::startTag('tbody', null); echo "\n";
-		$i = 0;
-		foreach ($rows as $row) {
-			$i++;
-			$trAttrs = array();
-			if (!empty($row['__js_on_click'])) $trAttrs['onClick'] = $row['__js_on_click'];
-			self::startTag('tr', $trAttrs); echo "\n";
-			if ($showLp) { self::tag('th', [ 'style' => "padding:2px; color:#ccc" ], $i); echo "\n"; }
+		if (!empty($cols)) {
+			self::startTag('thead', null); echo "\n";
+			self::startTag('tr', null); echo "\n";
+			if ($showLp) { self::tag('th', [ 'style' => "padding:2px" ], "Lp.");  echo "\n"; }
 			foreach ($cols as $colName) {
 				if (in_array($colName, $hiddenCols)) continue;
-				self::tag('td', [ 'style' => "padding:2px" ], V::get($colName, '', $row)); echo "\n";
+				self::tag('th', [ 'style' => "padding:2px"], $colName); echo "\n";
 			}
 			self::endTag('tr'); echo "\n";
+			self::endTag('thead'); echo "\n";
+		}
+		self::startTag('tbody', null); echo "\n";
+		if (empty($rows)) {
+			self::startTag('tr'); echo "\n";
+				self::tag('td', [ 'style' => "padding:2px" ], V::get('empty_msg', "Brak danych", $params)); echo "\n";
+			self::endTag('tr'); echo "\n";
+		} else {
+			$i = 0;
+			foreach ($rows as $row) {
+				$i++;
+				$trAttrs = array();
+				if (!empty($row['__js_on_click'])) $trAttrs['onClick'] = $row['__js_on_click'];
+				self::startTag('tr', $trAttrs); echo "\n";
+				if ($showLp) { self::tag('th', [ 'style' => "padding:2px; color:#ccc" ], $i); echo "\n"; }
+				foreach ($cols as $colName) {
+					if (in_array($colName, $hiddenCols)) continue;
+					self::tag('td', [ 'style' => "padding:2px" ], V::get($colName, '', $row)); echo "\n";
+				}
+				self::endTag('tr'); echo "\n";
+			}
 		}
 		self::endTag('tbody'); echo "\n";
 		self::endTag('table'); echo "\n";