<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Make table column header indicate the sort order of data in underlying search results? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Make-table-column-header-indicate-the-sort-order-of-data-in/m-p/449937#M127409</link>
    <description>&lt;P&gt;I &lt;EM&gt;am&lt;/EM&gt; surprised that this behavior is not already baked in to Splunk, at 7.3.x. Having tables reflect the default sort order of their data seems such an obvious thing to do. Is my use case so atypical? I understand that this might be a low priority, but still, isn't it "low-hanging fruit": relatively easy for the Splunk developers to add options to the table viz to support this behavior (say, &lt;CODE&gt;sortColumn&lt;/CODE&gt;, &lt;CODE&gt;sortOrder&lt;/CODE&gt;)?&lt;/P&gt;</description>
    <pubDate>Mon, 19 Aug 2019 09:08:56 GMT</pubDate>
    <dc:creator>Graham_Hanningt</dc:creator>
    <dc:date>2019-08-19T09:08:56Z</dc:date>
    <item>
      <title>Make table column header indicate the sort order of data in underlying search results?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Make-table-column-header-indicate-the-sort-order-of-data-in/m-p/449933#M127405</link>
      <description>&lt;P&gt;I want the sort indicators (up/down arrowheads) in table visualization column headings to reflect the default sort order of the data supplied by the underlying search.&lt;/P&gt;

&lt;P&gt;I'm using the &lt;CODE&gt;sort&lt;/CODE&gt; command in Splunk 7.3.0 to sort the search results for a table by one of the fields in descending order. So the rows of the table are already sorted. However, the sort indicators in the visualization don't reflect that default sort order.&lt;/P&gt;

&lt;P&gt;Instead of this:&lt;/P&gt;

&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="Screenshot of table showing figures sorted in descending order, but sort indicators do not reflect that order"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/7524i830D4DD08B87F385/image-size/large?v=v2&amp;amp;px=999" role="button" title="Screenshot of table showing figures sorted in descending order, but sort indicators do not reflect that order" alt="Screenshot of table showing figures sorted in descending order, but sort indicators do not reflect that order" /&gt;&lt;/span&gt;&lt;/P&gt;

&lt;P&gt;I want the table to show this, by default:&lt;/P&gt;

&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="Screenshot of table showing figures sorted in descending order, reflected by a sort indicator"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/7525i0425F60B9EFD7758/image-size/large?v=v2&amp;amp;px=999" role="button" title="Screenshot of table showing figures sorted in descending order, reflected by a sort indicator" alt="Screenshot of table showing figures sorted in descending order, reflected by a sort indicator" /&gt;&lt;/span&gt;&lt;/P&gt;

&lt;P&gt;(How) can I do this? There doesn't appear to be a corresponding formatting option to set the table visualization sort indicators.&lt;/P&gt;</description>
      <pubDate>Wed, 14 Aug 2019 06:15:47 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Make-table-column-header-indicate-the-sort-order-of-data-in/m-p/449933#M127405</guid>
      <dc:creator>Graham_Hanningt</dc:creator>
      <dc:date>2019-08-14T06:15:47Z</dc:date>
    </item>
    <item>
      <title>Re: Make table column header indicate the sort order of data in underlying search results?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Make-table-column-header-indicate-the-sort-order-of-data-in/m-p/449934#M127406</link>
      <description>&lt;P&gt;&lt;STRONG&gt;[UPDATED ANSWER]&lt;/STRONG&gt;&lt;BR /&gt;
Updated the answer to render the table only after search completes using &lt;CODE&gt;&amp;lt;done&amp;gt;&lt;/CODE&gt; and added a token dependency to apply &lt;CODE&gt;desc&lt;/CODE&gt; class to the icon for &lt;CODE&gt;count&lt;/CODE&gt; so that it shows down arrow only when dashboard loads. After which it should respond to click on the table header.&lt;/P&gt;

&lt;HR /&gt;

&lt;P&gt;@Graham_Hannington this would be possible through Simple XML JS Extension where on load of the table you can override the icon of table header using SplunkJS.&lt;/P&gt;

&lt;P&gt;In the following run anywhere example I have a table with &lt;CODE&gt;id="my_table_with_default_sort"&lt;/CODE&gt; which I am accessing via JS to override icon class as &lt;CODE&gt;desc&lt;/CODE&gt; to apply icon.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;&amp;lt;dashboard script="table_default_sort.js"&amp;gt;
  &amp;lt;label&amp;gt;Table with Sort&amp;lt;/label&amp;gt;
  &amp;lt;init&amp;gt;
    &amp;lt;set token="tokTableOnLoad"&amp;gt;true&amp;lt;/set&amp;gt;
  &amp;lt;/init&amp;gt;
  &amp;lt;row&amp;gt;
    &amp;lt;panel&amp;gt;
      &amp;lt;table id="my_table_with_default_sort" depends="$tokRenderTableOnSearchCompletion$"&amp;gt;
        &amp;lt;search&amp;gt;
          &amp;lt;query&amp;gt;index=_internal sourcetype=splunkd log_level!=INFO
| stats count by component
| sort 0 -count&amp;lt;/query&amp;gt;
          &amp;lt;done&amp;gt;
            &amp;lt;set token="tokRenderTableOnSearchCompletion"&amp;gt;true&amp;lt;/set&amp;gt;
          &amp;lt;/done&amp;gt;
          &amp;lt;earliest&amp;gt;-24h@h&amp;lt;/earliest&amp;gt;
          &amp;lt;latest&amp;gt;now&amp;lt;/latest&amp;gt;
          &amp;lt;sampleRatio&amp;gt;1&amp;lt;/sampleRatio&amp;gt;
        &amp;lt;/search&amp;gt;
        &amp;lt;option name="count"&amp;gt;20&amp;lt;/option&amp;gt;
        &amp;lt;option name="dataOverlayMode"&amp;gt;none&amp;lt;/option&amp;gt;
        &amp;lt;option name="drilldown"&amp;gt;none&amp;lt;/option&amp;gt;
        &amp;lt;option name="percentagesRow"&amp;gt;false&amp;lt;/option&amp;gt;
        &amp;lt;option name="rowNumbers"&amp;gt;false&amp;lt;/option&amp;gt;
        &amp;lt;option name="totalsRow"&amp;gt;false&amp;lt;/option&amp;gt;
        &amp;lt;option name="wrap"&amp;gt;true&amp;lt;/option&amp;gt;
      &amp;lt;/table&amp;gt;
    &amp;lt;/panel&amp;gt;
  &amp;lt;/row&amp;gt;
&amp;lt;/dashboard&amp;gt;
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Following is the required JS &lt;CODE&gt;table_default_sort.js&lt;/CODE&gt;&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;require(["jquery",
         "splunkjs/mvc",
         "splunkjs/mvc/tableview",
         "splunkjs/mvc/simplexml/ready!"],
 function ($,
          mvc,
          TableView) {
    var defaultTokenModel=mvc.Components.get("default");

    mvc.Components.get('my_table_with_default_sort').getVisualization(function (tableView) {
        tableView.on('rendered', function () {
            setTimeout(function(){
                var strTokTableOnLoad=defaultTokenModel.get("tokTableOnLoad");
                // Get the Token tokTableOnLoad which is set in the &amp;lt;init&amp;gt; section for the first time override of table sort icon for count column
                if(strTokTableOnLoad!==undefined){
                $('#my_table_with_default_sort table th[data-sort-key="count"] a i').addClass("desc");
                    // Unset the token tokTableOnLoad so that Table icon override never happens for the second time.
                    defaultTokenModel.unset("tokTableOnLoad");
                }
            },100);
        });
    });
});
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Please try out and confirm!&lt;/P&gt;</description>
      <pubDate>Wed, 14 Aug 2019 10:24:33 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Make-table-column-header-indicate-the-sort-order-of-data-in/m-p/449934#M127406</guid>
      <dc:creator>niketn</dc:creator>
      <dc:date>2019-08-14T10:24:33Z</dc:date>
    </item>
    <item>
      <title>Re: Make table column header indicate the sort order of data in underlying search results?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Make-table-column-header-indicate-the-sort-order-of-data-in/m-p/449935#M127407</link>
      <description>&lt;P&gt;Hi @niketnilay,&lt;/P&gt;

&lt;P&gt;With apologies for the belated reply (I was on leave for a couple of days): thanks very much! Yes, that worked!&lt;/P&gt;

&lt;P&gt;&lt;STRONG&gt;Nit:&lt;/STRONG&gt; to get your code to work, I had to change &lt;CODE&gt;tokRenderTableOnSearchCompletion&lt;/CODE&gt; in the dashboard source to match the corresponding token name &lt;CODE&gt;tokTableOnLoad&lt;/CODE&gt; in the JavaScript. At least—I write this in case I'm completely misunderstanding something here—it didn't work at first, and then I made that change, and then it worked.&lt;/P&gt;

&lt;P&gt;So... I suppose I should accept your answer immediately. And, if that's what you'd prefer, after reading the rest of this comment, I'll do just that.&lt;/P&gt;

&lt;P&gt;Your current answer works for a specific table: with hardcoded table ID, sorted column name, and sort order.&lt;/P&gt;

&lt;P&gt;I want to apply this behavior to multiple tables on a dashboard. I don't want to create a separate &lt;CODE&gt;.js&lt;/CODE&gt; file for each table. I can't bring myself to implement this answer in code that I'm going to deliver to customers. (My problem? Sure.)&lt;/P&gt;

&lt;P&gt;I've started experimenting with JavaScript that will iterate over all table views in a dashboard:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;$.each(mvc.Components.getInstances(), function (i, view) {
  if (view instanceof TableView) {
    view.on('rendered', function(view) {setDefaultSort(view)});
  }
});
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;but tokens are—unless I'm mistaken; I might be—by definition &lt;EM&gt;dashboard-wide&lt;/EM&gt;, not &lt;EM&gt;view-specific&lt;/EM&gt;, so this token-based approach does not work for multiple views in a dashboard.&lt;/P&gt;

&lt;P&gt;I've started to look into other ways to pass a sort column name and sort order through to the JavaScript, and to have the rendering occur only on page load, but I feel like I'm heading down a developmental rabbit hole (custom visualization?) that I don't have time to explore.&lt;/P&gt;

&lt;P&gt;Your thoughts?&lt;/P&gt;</description>
      <pubDate>Mon, 19 Aug 2019 08:53:28 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Make-table-column-header-indicate-the-sort-order-of-data-in/m-p/449935#M127407</guid>
      <dc:creator>Graham_Hanningt</dc:creator>
      <dc:date>2019-08-19T08:53:28Z</dc:date>
    </item>
    <item>
      <title>Re: Make table column header indicate the sort order of data in underlying search results?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Make-table-column-header-indicate-the-sort-order-of-data-in/m-p/449936#M127408</link>
      <description>&lt;P&gt;Extending the table cell renderer initially occurred to me as a possibility, but it seems that the cell renderer is limited to the table &lt;EM&gt;body&lt;/EM&gt; cells (td); I can't find a way to extend the rendering of the table &lt;EM&gt;header&lt;/EM&gt; cells (th).&lt;/P&gt;</description>
      <pubDate>Mon, 19 Aug 2019 08:59:29 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Make-table-column-header-indicate-the-sort-order-of-data-in/m-p/449936#M127408</guid>
      <dc:creator>Graham_Hanningt</dc:creator>
      <dc:date>2019-08-19T08:59:29Z</dc:date>
    </item>
    <item>
      <title>Re: Make table column header indicate the sort order of data in underlying search results?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Make-table-column-header-indicate-the-sort-order-of-data-in/m-p/449937#M127409</link>
      <description>&lt;P&gt;I &lt;EM&gt;am&lt;/EM&gt; surprised that this behavior is not already baked in to Splunk, at 7.3.x. Having tables reflect the default sort order of their data seems such an obvious thing to do. Is my use case so atypical? I understand that this might be a low priority, but still, isn't it "low-hanging fruit": relatively easy for the Splunk developers to add options to the table viz to support this behavior (say, &lt;CODE&gt;sortColumn&lt;/CODE&gt;, &lt;CODE&gt;sortOrder&lt;/CODE&gt;)?&lt;/P&gt;</description>
      <pubDate>Mon, 19 Aug 2019 09:08:56 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Make-table-column-header-indicate-the-sort-order-of-data-in/m-p/449937#M127409</guid>
      <dc:creator>Graham_Hanningt</dc:creator>
      <dc:date>2019-08-19T09:08:56Z</dc:date>
    </item>
    <item>
      <title>Re: Make table column header indicate the sort order of data in underlying search results?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Make-table-column-header-indicate-the-sort-order-of-data-in/m-p/449938#M127410</link>
      <description>&lt;P&gt;I've accepted this answer because it works for the question I asked. @niketnilay deserves credit for that.&lt;/P&gt;

&lt;P&gt;However, there's a caveat: I can't—or rather, won't—be using this answer in practice, because, in my opinion, it's too onerous to implement. The code presented in this answer is specific to a particular table visualization. I'm considering asking a new, follow-on, more carefully worded question to address this.&lt;/P&gt;</description>
      <pubDate>Fri, 23 Aug 2019 05:49:48 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Make-table-column-header-indicate-the-sort-order-of-data-in/m-p/449938#M127410</guid>
      <dc:creator>Graham_Hanningt</dc:creator>
      <dc:date>2019-08-23T05:49:48Z</dc:date>
    </item>
    <item>
      <title>Re: Make table column header indicate the sort order of data in underlying search results?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Make-table-column-header-indicate-the-sort-order-of-data-in/m-p/449939#M127411</link>
      <description>&lt;P&gt;@Graham_Hannington thanks for accepting the answer. And trust me I have got your followup question for making this generic for all tableViews in the dashboard. Which is doable, but I would be able to spend time for creating an example only o we the weekend. So hang tight (hopefully I get to spend time as I have pipelinedquite many such challenges for the weekend).&lt;/P&gt;</description>
      <pubDate>Fri, 23 Aug 2019 05:55:12 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Make-table-column-header-indicate-the-sort-order-of-data-in/m-p/449939#M127411</guid>
      <dc:creator>niketn</dc:creator>
      <dc:date>2019-08-23T05:55:12Z</dc:date>
    </item>
    <item>
      <title>Re: Make table column header indicate the sort order of data in underlying search results?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Make-table-column-header-indicate-the-sort-order-of-data-in/m-p/708963#M239658</link>
      <description>&lt;P&gt;Old post, but managed without Javascript and CSS oneliner.&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;Set a table ID like (my_table_with_default_sort),&lt;/LI&gt;&lt;LI&gt;In CSS, apply a fixed or dynamic data-sort-key to the colomn you want to sort. In this example token is used matches with the sort used in the query.&lt;/LI&gt;&lt;/OL&gt;&lt;LI-CODE lang="css"&gt;#my_table_with_default_sort table th[data-sort-key="$tok_sort_column$"] a i::before
content: "↥"; /* for ASC*, for DESC use "↧";  */
display: inline-block;
font-size: 12px;
margin-right: 5px;
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 16 Jan 2025 10:24:51 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Make-table-column-header-indicate-the-sort-order-of-data-in/m-p/708963#M239658</guid>
      <dc:creator>tcdbruijn</dc:creator>
      <dc:date>2025-01-16T10:24:51Z</dc:date>
    </item>
  </channel>
</rss>

