ocket8888 commented on a change in pull request #3680: TP: adds the ability to 
rearrange table columns as well as toggle column visibility/searchability
URL: https://github.com/apache/trafficcontrol/pull/3680#discussion_r295857471
 
 

 ##########
 File path: 
traffic_portal/app/src/common/modules/table/types/TableTypesController.js
 ##########
 @@ -33,15 +37,34 @@ var TableTypesController = function(types, $scope, $state, 
locationUtils) {
         $state.reload(); // reloads all the resolves for the view
     };
 
+    $scope.toggleVisibility = function(colName) {
+        const col = table.column(colName + ':name');
+        col.visible(!col.visible());
+        table.rows().invalidate().draw();
+    };
+
     angular.element(document).ready(function () {
-        $('#typesTable').dataTable({
-            "aLengthMenu": [[25, 50, 100, -1], [25, 50, 100, "All"]],
-            "iDisplayLength": 25,
-            "aaSorting": []
-        });
+        table = $('#typesTable').DataTable({
+                "lengthMenu": [[25, 50, 100, -1], [25, 50, 100, "All"]],
+                "iDisplayLength": 25,
+                "aaSorting": [],
+                "columns": [
+                    { "name": "name", "visible": true, "searchable": true },
+                    { "name": "description", "visible": true, "searchable": 
true },
+                    { "name": "lastUpdated", "visible": false, "searchable": 
false },
+                    { "name": "useInTable", "visible": true, "searchable": 
true }
+                ],
+                "colReorder": {
+                    realtime: false
+                },
+                "initComplete": function(settings, json) {
+                    // need to create the show/hide column checkboxes and bind 
to the current visibility
+                    $scope.columns = 
JSON.parse(localStorage.getItem('DataTables_typesTable_/')).columns;
 
 Review comment:
   You should still handle this error, because an error thrown by `JSON.parse` 
doesn't necessarily mean that `localStorage` isn't working - the locally stored 
data could have been corrupted somehow etc. Stack traces from an angular 
compile cycle are very hard to follow, so even if all you do with the error is 
log it to the console it could aid in debugging.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to