From a10e0bc36c062052f0834c4fa4f7ffed852d297b Mon Sep 17 00:00:00 2001
From: Benjamin Bertrand <benjamin.bertrand@esss.se>
Date: Tue, 2 Oct 2018 23:15:07 +0200
Subject: [PATCH] Fix Cannot read property '_buttons' of undefined

The buttons should only be created if the items_table exists

JIRA INFRA-584
---
 app/static/js/items.js | 24 +++++++++++++-----------
 1 file changed, 13 insertions(+), 11 deletions(-)

diff --git a/app/static/js/items.js b/app/static/js/items.js
index 5729188..5eeccef 100644
--- a/app/static/js/items.js
+++ b/app/static/js/items.js
@@ -93,18 +93,20 @@ $(document).ready(function() {
     ]
   });
 
-  new $.fn.dataTable.Buttons(items_table, {
-    buttons: [
-      {
-        text: '<span class="oi oi-data-transfer-download" title="Export to excel file" aria-hidden="true"></span> Excel',
-        className: "btn-outline-secondary",
-        action: function ( e, dt, node, conf ) {
-          download_excel();
+  if( $("#items_table").length ) {
+    new $.fn.dataTable.Buttons(items_table, {
+      buttons: [
+        {
+          text: '<span class="oi oi-data-transfer-download" title="Export to excel file" aria-hidden="true"></span> Excel',
+          className: "btn-outline-secondary",
+          action: function ( e, dt, node, conf ) {
+            download_excel();
+          }
         }
-      }
-    ]
-  });
+      ]
+    });
 
-  items_table.buttons().container().appendTo("#items_table_wrapper .col-md-3:eq(0)");
+    items_table.buttons().container().appendTo("#items_table_wrapper .col-md-3:eq(0)");
+  }
 
 });
-- 
GitLab