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_r295876093
 
 

 ##########
 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:
   Yeah, a simple
   
   ```javascript
   try {
       doThing()
   } catch e {
       console.error("Failed to load columns from localStorage:", e)
       // optional fallback column assignment here (not sure if that's 
necessary)
   }
   ```
   
   would be fine IMO. Esp. since that error could propagate upward and mess up 
the whole UI, not sure what that would look like.

----------------------------------------------------------------
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