• kiran b sfdc
  • NEWBIE
  • 0 Points
  • Member since 2018

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 1
    Replies
I'm using lightning dataTable component.  But the sortedDirection only ever sorts one direction.  The sortDirection param never updates properly. Here is some code:
 
<aura:component implements="flexipage:availableForAllPageTypes" 
                controller="CrossSellActivityController"
                access="global">

  <!-- Attributes -->
  <aura:attribute name="activities" type="Array" />
  <aura:attribute type="String" name="sortedDirection" default="asc" />
  <aura:attribute name="columns" type="List" />

  <!-- Component DOM -->
  <div>
    <lightning:datatable keyField="id"
                         data="{!v.activities}"
                         columns="{!v.columns}"
                         sortedDirection="{!v.sortedDirection}"
                         onsort="{!c.updateColumnSorting}"
                         hideCheckboxColumn="true" />
  </div>

</aura:component>
Here is the column definition:
var columns = [
  { label: 'Program Key', fieldName: 'Program_Key__c', type: 'text', sortable: true },
  { label: 'Status', fieldName: 'Disposition__c', type: 'text', sortable: true },
  { label: 'User', fieldName: 'Username', type: 'text', sortable: true },
  { label: 'Asset', fieldName: 'Asset', type: 'text', sortable: true },
  { 
    label: 'Timestamp', 
    fieldName: 'CreatedDate', 
    type: 'date', 
    typeAttributes: {
      day: 'numeric',
      month: 'short',
      year: 'numeric',
      hour: '2-digit',
      minute: '2-digit',
      second: '2-digit',
      hour12: true
    },
    sortable: true
  }
];
component.set("v.columns", columns);
And where I console.log out the sortedDirection variable:
updateColumnSorting : function(component, event, helper) {
  var sortDirection = event.getParam('sortDirection');        
  component.set("v.sortedDirection", sortDirection);
  console.log('sortDirection: ', sortDirection);
},
The console.log always outputs 'asc' never flips to 'desc'.  I've even tried changing the definition to Boolean with no luck.
<aura:attribute type="Boolean" name="sortedDirection" default="false" />
I've also tried flipping it myself with a truthy check and setting it back on the sortedDirection attribute, but that doesn't work either.  Am I doing something wrong?