Dashboards & Visualizations

Expand table raw using custom row expansion

jamesvillil
Engager

Hi All,

I'm trying to create a table with option to expand and collapse row data using 'custom row expansion'. I managed to apply the js to enable row expansion but unable to manage text wrap on collapse.

I'd like to disable text wrap and show only one line of cell data when row is collapsed. I saw the similar functionality in Splunk Search History view but not sure how to apply it in normal table. Please can someone help me with this?

My Table:

my_table.png

Search History View:

search_history_1.png

search_history_2.png

xml:

 

<dashboard script="expand_table.js">
  <label>Test Dashboard</label>
  <row>
    <panel>
      <table id="test_table">
        <title>Search View</title>
        <search>
          <query>index=_audit info=granted search_id=* search=*
| table _time info search search_id</query>
          <earliest>-24h@h</earliest>
          <latest>now</latest>
        </search>
        <option name="drilldown">none</option>
        <option name="refresh.display">progressbar</option>
      </table>
    </panel>
  </row>
  <row>
    <panel depends="$alwaysHideCSSPanel$">
      <html>
        <style>
          #test_table th:nth-child(5),
          #test_table td:nth-child(5),
          #test_table th:nth-child(2),
          #test_table td:nth-child(2),
          #test_table th:nth-child(3),
          #test_table td:nth-child(3),
          #test_table th:nth-child(4),
          #test_table td:nth-child(4){
              width: 25% !important;
              overflow: hidden !important;
              text-overflow: ellipsis !important;
          }
        </style>
      </html>
    </panel>
  </row>
</dashboard>

 

 

js:

 

require([
        "underscore",
        "splunkjs/mvc",
        "splunkjs/mvc/searchmanager",
        "splunkjs/mvc/tableview",
        "splunkjs/mvc/simplexml/ready!"
    ], function(
       _,
       mvc,
       SearchManager,
       TableView
    ) {

    // Create a table


    // Create a basic custom row renderer
    var BasicRowRenderer = TableView.BaseRowExpansionRenderer.extend({
        canRender: function(rowData) {

            console.log("RowData: ", rowData);

            return true;
        },

        render: function($container, rowData) {
            // Print the rowData object to the console
            console.log("RowData: ", rowData);

            // Display some of the rowData in the expanded row
            $container.append('<div>'
                + '<b>rowIndex</b>: ' + rowData.rowIndex + '<br>'
                + '<b>colspan</b>: ' + rowData.colspan + '<br>'
                + '<b>fields</b>: ' + rowData.fields + '<br>'
                + '<b>values</b>: ' + rowData.values
                + '</div>');
        }
    });

    var tableElement = mvc.Components.getInstance("test_table");
    tableElement.getVisualization(function(tableView) {
        // Add custom cell renderer, the table will re-render automatically.
        tableView.addRowExpansionRenderer(new BasicRowRenderer());
    });
});

 

 

Thank you

Labels (4)
0 Karma

kamlesh_vaghela
SplunkTrust
SplunkTrust

@jamesvillil 

Can you please try this?

 

<html>
        <style>
          #test_table th:nth-child(5),
          #test_table td:nth-child(5),
          #test_table th:nth-child(2),
          #test_table td:nth-child(2),
          #test_table th:nth-child(3),
          #test_table td:nth-child(3),
          #test_table th:nth-child(4),
          #test_table td:nth-child(4){
              max-width: 75ch !important;
              min-width: 25% !important;
              overflow: hidden;
              white-space: nowrap !important;;
              text-overflow: ellipsis !important;
          }
        </style>
      </html>

 

 

Screenshot 2021-11-05 at 11.33.51 AM.png

 

Thanks
KV
▄︻̷̿┻̿═━一   😉

If any of my reply helps you to solve the problem Or gain knowledge, an upvote would be appreciated.

jamesvillil
Engager

Thanks @kamlesh_vaghela, that worked like a charm! 👍

Is it possible to disable the hide while clicking on row  expand arrow? I mean show full content (like table with wrap) on expansion and hide overflow (like you did above) when it collapsed. Similar to what search history is doing.

 

Thank you

0 Karma

kamlesh_vaghela
SplunkTrust
SplunkTrust

@jamesvillil 

May be you should add code in JS for apply logic on clicking on row  expand arrow. I didn't tried but it should work.

KV

0 Karma
Get Updates on the Splunk Community!

Detecting Remote Code Executions With the Splunk Threat Research Team

REGISTER NOWRemote code execution (RCE) vulnerabilities pose a significant risk to organizations. If ...

Observability | Use Synthetic Monitoring for Website Metadata Verification

If you are on Splunk Observability Cloud, you may already have Synthetic Monitoringin your observability ...

More Ways To Control Your Costs With Archived Metrics | Register for Tech Talk

Tuesday, May 14, 2024  |  11AM PT / 2PM ET Register to Attend Join us for this Tech Talk and learn how to ...