How to sort child table doc type by specific column


any solution to sort the child table doctype like below “Item Attribute Value” on form load for example or on save , as i have more than 100 attribute value and i want to be sorted by alphabetical for example for specific column like “attribute_value”,

Thanks for your reply

But can you guide me how to use , this is server script right ??

so i changed below code

server side :

def validate(self):
for i, item in enumerate(sorted(self.item_attribute_values, key=lambda item : item_attribute_values.attribute_value), start=1):
item.idx = i

client side :

var idx = 1;
if (a.attribute_value < b.attribute_value){ return -1 }
else if ( a.attribute_value > b.attribute_value){ return 1 }
return 1;
attribute_value.idx = idx++;

and unfortunately not working

Hi, I’m interested too about this fact. Did you find a solution ?

Hi, I am also trying to do this. Anyone got solution. Please tell me. Thanks.

no till now

ok. thanks

I tried this, and it worked

It would be really nice if there was some kind of customizable sort feature built into the tables. This would be really convenient to change the sort on the fly.


// function call

frm.cscript.sort_child_table_based_on_field_name("items", "item_code");

// function definition

cur_frm.cscript.sort_child_table_based_on_field_name: function(table_name, field_name){
	cur_frm.doc[table_name].sort(function (x, y) {
	    return x[field_name]  - y[field_name];
	$.each(cur_frm.doc[table_name] || [], function(i, d) {
		d.idx = i+1;
		refresh_field("idx",, d.parentfield);