Expand my Community achievements bar.

Enhance your AEM Assets & Boost Your Development: [AEM Gems | June 19, 2024] Improving the Developer Experience with New APIs and Events

can i sort data in a table?

Avatar

Former Community Member
hi everybody,



i have a table loading xml-data. i want the user to be able to resort the loaded data. is there a way to do it?



thanks very much,

valerio
3 Replies

Avatar

Former Community Member
There's no way built into the Table object to sort the data; you'd either need to sort it at the source, or write JavaScript code to sort it - there's a sort method for a JavaScript array, so if you can get the elements into an array, you can sort the array and then populate the table from that.

--

SteveX

Adobe Systems

Avatar

Former Community Member
hi stevex and everybody,<br /><br />yes this is exactly what i did and it works fine. eventhough the performance could be very low, depending on the amount of objects you have to check to build up your array.<br /><br />my case:<br />form1.subform[0] instancieted n-times.<br />dropdownlist with sort parameters () and a button.<br /><br />var sSortParam=xfa.resolveNode("SortParam").rawValue; // my <br /> // dropdownlist<br /><br />switch(sSortParam){<br /><br /> case "0":<br /> sSortParam="Param1";<br /> break;<br /><br /> case "1":<br /> sSortParam="Param2";<br /> break;<br /><br /> case "2":<br /> sSortParam="Param3";<br /> break;<br /><br /> case "3":<br /> sSortParam="Param4";<br /> break;<br /><br /> case "4":<br /> sSortParam="Param5";<br /> break;<br />}<br /><br />// myVars is a variables collecting object in my script object<br />myVars.mySort=new Array(0); // reset the array for each sort operation<br />// myVars is a functions collecting object in my script object<br />myFuncs.sortSubforms(sSortParam);<br /><br />// my function sortSubforms<br />function sortSubforms(sSortParam){<br /><br /> // Number of subforms at the time of the call.<br /> var oSubform=xfa.resolveNodes("Gewerberegister.subform[*]");<br /> var nSubformLength0=oSubform.length;<br /><br /> // build the array<br /> for(i=0; i<nSubformLength0; i++){<br /><br /> var sField2BSorted = xfa.resolveNode("Gewerberegister.subform[" + i + "]."+sSortParam).rawValue;<br /> var singleSubform =new Array();<br /> singleSubform.push(sField2BSorted, i);<br /><br /> myVars.mySort.push(singleMeldung);<br /> }<br /><br /> var nSortLength=myVars.mySort.length;<br /><br /> // sort my array.<br /> myVars.mySort.sort();<br /><br /> // reset the subforms according with the sorted array.<br /> for(j=0; j<nSortLength; j++){<br /><br /> var nSourceSubformInx=myVars.mySort[j][1];<br /> xfa.resolveNode("form1.subform[0]").instanceManager.addInstance(1);<br /><br /> var oSubform =xfa.resolveNodes("form1.subform[*]");<br /> var nSubformLengthNew = oSubform.length;<br /><br /> xfa.resolveNode("form1.subform[" + (nSubformLengthNew-1) + "].subformField1").rawValue =xfa.resolveNode("form1.subform[" + nSourceSubformInx + "].subformField1").rawValue;<br /><br /> }<br /><br /> // get rid of the old subforms.<br /> for(a=(nSubformLength0-1); a>-1; a--){<br /> xfa.resolveNode("form1.subform").instanceManager.removeInstance(a);<br /><br /> }<br />}<br /><br />this worked fine to me. i hope it helps !!

Avatar

Level 1

Hi Valerio,

Would you be able to share a pdf where you utilize this functionality?

Thanks,


Mark