Skip to content

Commit

Permalink
Update scripts.blade.php
Browse files Browse the repository at this point in the history
Chekc if the data column is a json field
  • Loading branch information
wimurk authored May 6, 2021
1 parent eb3d402 commit fbf6bfa
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion src/resources/views/scripts.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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
Expand Down

0 comments on commit fbf6bfa

Please sign in to comment.