From fbf6bfaabed6168c4a82d2e587ff60002b0ed0e7 Mon Sep 17 00:00:00 2001 From: Wimurk Date: Thu, 6 May 2021 15:35:26 +0200 Subject: [PATCH] Update scripts.blade.php Chekc if the data column is a json field --- src/resources/views/scripts.blade.php | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/src/resources/views/scripts.blade.php b/src/resources/views/scripts.blade.php index 7d4d4cc..3fe0353 100644 --- a/src/resources/views/scripts.blade.php +++ b/src/resources/views/scripts.blade.php @@ -284,7 +284,7 @@ classes["{{ $view->tableId }}"] = new class } //Empty check - if(view.emptyCheck && (!data || (isNaN(data) && !data.length))){ + if(view.emptyCheck && (!data || (isNaN(data) && !data.length && !this.isJson(data)))){ output += `${view.before || ''} ${view.returnWhenEmpty || ''} ${view.after || ''}`; continue; } @@ -306,6 +306,31 @@ function ${def.id}${def.index}(){ //return the columns return defsArray; } + + /** + * Check if parameter is a json string + * + * @param {String} item + * @type Arguments + */ + isJson(item) + { + item = typeof item !== "string" + ? JSON.stringify(item) + : item; + + try { + item = JSON.parse(item); + } catch (e) { + return false; + } + + if (typeof item === "object" && item !== null) { + return true; + } + + return false; + } /** * Return the new data key