You need to sign in to do that
Don't have an account?
Eric Teseur
Sort checked row
I have a tab where i save my values in Unsorted column. And when I check checkbox I want to copy value from Unsorted column then sort it and save in Sorted column
Use Below code it works properly for the whole number and a decimal number.
@AuraEnabled
public static void saveInput(List < ApexSort__c > ListApexSort) {
Insert ListApexSort;
}
@AuraEnabled
public List < ApexSort__c > accList = new List < ApexSort__c > ();
@AuraEnabled
public List < ApexSort__c > sortRec = new List < ApexSort__c > ();
@AuraEnabled(cacheable = true)
public static List < ApexSort__c > getArray(String query) {
accListClass alc = new accListClass();
alc.accList = Database.query('SELECT Id, Unsorted__c, Sorted__c FROM ApexSort__c order by LastModifiedDate desc LIMIT 10');
return alc.accList;
}
@AuraEnabled
public static List < ApexSort__c > sortSlctRec(List < String > slctRec) {
List < ApexSort__c > sortRec = new List < ApexSort__c > ();
accListClass alc = new accListClass();
ApexSort__c sortApRec = [SELECT Id, Unsorted__c, Sorted__c FROM ApexSort__c WHERE Id IN: slctRec];
try {
for(ApexSort__c sortobj : sortApRec){
String sortString = sortobj.Unsorted__c;
List<String> sortList = sortString.split(',');
List<Decimal> intList = new List<Decimal>();
for(String s : sortList){
intList.add(Decimal.valueOf(s));
}
intList.sort();
sortString = string.join(intList,',');
sortobj.Sorted__c = sortString;
sortRec.add(sortobj);
}
update sortRec;
} catch (Exception ex) {
throw new AuraHandledException(ex.getMessage());
}
alc.accList = Database.query('SELECT Id, Unsorted__c, Sorted__c FROM ApexSort__c LIMIT 10');
return alc.accList;
}
Thanks.
All Answers
You need to make a wrapper in javascript helper when you click chekbox then go to js heper method and get that particular raw record and updated(add sorted value) it by using wrapper.
I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.
Thanks,
Ajay Dubedi
Greetings to you!
- I read your problem and implemented in my Org.
- Please use the below code [Solved] : -
Component : -
Controller JS : -
Helper JS : -
Class : -
I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.
Thanks and Regards,
Deepali Kulshrestha.
Hi, Deepali
Thanks for your answer, all are working fine. But i want solve it with apex side, here is my code:
How to implement sort of sortApRec ? (built-in sorting apex functions doesn`t work) Any suggestions?Use below code it may helpful for you
I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.
Thanks,
Ajay Dubedi
Use Below code it works properly for the whole number and a decimal number.
@AuraEnabled
public static void saveInput(List < ApexSort__c > ListApexSort) {
Insert ListApexSort;
}
@AuraEnabled
public List < ApexSort__c > accList = new List < ApexSort__c > ();
@AuraEnabled
public List < ApexSort__c > sortRec = new List < ApexSort__c > ();
@AuraEnabled(cacheable = true)
public static List < ApexSort__c > getArray(String query) {
accListClass alc = new accListClass();
alc.accList = Database.query('SELECT Id, Unsorted__c, Sorted__c FROM ApexSort__c order by LastModifiedDate desc LIMIT 10');
return alc.accList;
}
@AuraEnabled
public static List < ApexSort__c > sortSlctRec(List < String > slctRec) {
List < ApexSort__c > sortRec = new List < ApexSort__c > ();
accListClass alc = new accListClass();
ApexSort__c sortApRec = [SELECT Id, Unsorted__c, Sorted__c FROM ApexSort__c WHERE Id IN: slctRec];
try {
for(ApexSort__c sortobj : sortApRec){
String sortString = sortobj.Unsorted__c;
List<String> sortList = sortString.split(',');
List<Decimal> intList = new List<Decimal>();
for(String s : sortList){
intList.add(Decimal.valueOf(s));
}
intList.sort();
sortString = string.join(intList,',');
sortobj.Sorted__c = sortString;
sortRec.add(sortobj);
}
update sortRec;
} catch (Exception ex) {
throw new AuraHandledException(ex.getMessage());
}
alc.accList = Database.query('SELECT Id, Unsorted__c, Sorted__c FROM ApexSort__c LIMIT 10');
return alc.accList;
}
Thanks.
Hi Ajay
Thank you, all is working awesome. With your help I`m solved like this:
Greetings to you!
- I read your problem and implemented in my Org.
- Please use the below code [Solved] : -
I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.
Thanks and Regards,
Deepali Kulshrestha.