I'm trying to use Sorting Datatable //cdn.datatables.net/1.10.12/css/jquery.dataTables.css
and //cdn.datatables.net/1.10.12/js/jquery.dataTables.js
in Salesforce Lightning Component. I've included required library files. It is working in normal table. Not working in when i used in aura:iteration to display a table. See below image.
Component:
<aura:component controller="sortViewLead" implements="forceCommunity:availableForAllPageTypes" access="global">
<ltng:require styles="/resource/customsortingDT/customsortingDT/jquery.dataTables.css"
scripts="/resource/jquery1,/resource/customsortingDT/customsortingDT/jquery.dataTables.js"
afterScriptsLoaded="{!c.jsLoaded}" />
<aura:attribute name="lstLeads" type="list"/>
<aura:handler name="init" value="{!this}" action="{!c.doInit}" />
<table id="extable" class="display" cellspacing="0" width="100%">
<thead>
<tr>
<th>Name</th>
<th>Position</th>
<th>Office</th>
<th>Age</th>
<th>Start date</th>
<th>Salary</th>
</tr>
</thead>
<tbody>
<tr>
<td>Tiger Nixon</td>
<td>System Architect</td>
<td>Edinburgh</td>
<td>61</td>
<td>2011/04/25</td>
<td>$320,800</td>
</tr>
<tr>
<td>Garrett Winters</td>
<td>Accountant</td>
<td>Tokyo</td>
<td>63</td>
<td>2011/07/25</td>
<td>$170,750</td>
</tr>
<tr>
<td>Ashton Cox</td>
<td>Junior Technical Author</td>
<td>San Francisco</td>
<td>66</td>
<td>2009/01/12</td>
<td>$86,000</td>
</tr>
<tr>
<td>Cedric Kelly</td>
<td>Senior Javascript Developer</td>
<td>Edinburgh</td>
<td>22</td>
<td>2012/03/29</td>
<td>$433,060</td>
</tr>
</tbody>
</table>
<table id="exdumdp" class="display" cellspacing="0" width="100%">
<thead>
<tr>
<th>Name</th>
<th>Company</th>
</tr>
</thead>
<tbody>
<aura:iteration var="d" items="{!v.lstLeads}" >
<tr>
<td>{!d.Name}</td>
<td>{!d.Company}</td>
</tr>
</aura:iteration>
</tbody>
</table>
</aura:component>
({
doInit : function(component, event,helper) {
console.log('Inside Doinit');
var action = component.get("c.getLeads");
console.log(action);
action.setCallback(this,function(a){
//get the response state
var state = a.getState();
//check if result is successfull
console.log(state);
if(state == "SUCCESS"){
var result = a.getReturnValue();
component.set("v.lstLeads",result);
}
else if(state == "ERROR"){
alert('Error in calling server side action');
}
//adds the server-side action to the queue
});
$A.enqueueAction(action);
},
jsLoaded: function(component, event, helper) {
console.log('Inside Jquery');
var j$ = jQuery.noConflict();
//Task Datatable
j$('#extable,exdumdp').DataTable();
}
})
/**
For Testing
**/
public without sharing class sortViewLead{
@AuraEnabled
public List<Lead> getLeads1() {
List<Lead> lstacc = [SELECT id,Name,Company FROM Lead LIMIT 5];
system.debug('!!!'+lstacc );
return lstacc ;
}
@AuraEnabled
public static List<Lead> getLeads() {
sortViewLead d = new sortViewLead();
return d.getLeads1();
}
}