How to sort child table

hello,

is there any code example for sorting child table?

thank you.

Just click on the header of the child table. You can also pick child table field to filter report based on.

hello,

thank you for your reply.

i am sorry that my question is not clear enough. for example, how can i sort the “items” child table in Sales Order?

i know we could drag to arrange order manually, but i would like to code it to sort automatically and save to database.

is there any code example for sorting child table?

thank you.

Yes I also need to sort a child table. How can I do this?

This looks like a report and not a child table in sales order, for example. How can we sort a child table? I would like to sort items by item number on the sales order item child table, for instance.

I thought that entering how I wanted this sorted here would work but it doesn’t:

Any ideas?

function rankingSorter(firstKey) {
        return function(a, b) {  
            if (a[firstKey] < b[firstKey]) {  
                return -1;  
            } else if (a[firstKey] < b[firstKey]) {  
                return 1;  
            }  
            else {
                return 0;
            } 
        }  
    }

for example you have field in child table(properties_list ) called sales_properties
cur_frm.doc.properties_list = [
{sales_properties: “7413” },
{sales_properties: “6986” },
{sales_properties: “6858” },
{sales_properties: “6899” },
];

            var sorted = cur_frm.doc.properties_list.sort(rankingSorter("sales_properties"));
        	for(var i=0; i < sorted.length; i++) {
             console.log(sorted[i])
        	 sorted[i].idx = i;
            }
        	cur_frm.doc.refresh_fields();

if still stuck check this link
https://www.mydatahack.com/sorting-json-by-multiple-keys-with-javascript/#:~:text=JavaScript’s%20sort()%20method%20sorts,data%20can%20be%20easily%20sorted.