How to change the Sorting of Link Fields

Hi,

I would like to know if it is possible to sort the results of a link field ALPHABETICALLY instead of by the last edited sorting that the system follows by default.

Whether I need to put a custom client side script or  custom server side script for the same. 



Note:

 

If you are posting an issue,

  1. We should be able to replicate it at our end. So please give us as much information as you can. Please see it from the point of view of the person receiving the communication.
  2. Paste your code at http://pastebin.com or http://gist.github.com and send only the URL via email
  3. For sending images, use http://imgur.com or other similar services. Do not send images as attachments. Links are good. Same goes for any file you are going to send.

     

    End of Note



    You received this message because you are subscribed to the Google Groups “ERPNext Developer Forum” group.

    To unsubscribe from this group and stop receiving emails from it, send an email to erpnext-developer-forum+un…@googlegroups.com.

    To view this discussion on the web visit https://groups.google.com/d/msgid/erpnext-developer-forum/dfaa8019-b67a-401a-bf7d-ef1f520425d4%40googlegroups.com.

    For more options, visit https://groups.google.com/d/optout.
Aditya,

In version 4 there is a Sort By and Sort Field setting you can do via Customize Form view.


@rushabh_mehta

On 29-May-2014, at 11:56 am, Aditya Duggal <ad...@gmail.com> wrote:

Hi,

I would like to know if it is possible to sort the results of a link field ALPHABETICALLY instead of by the last edited sorting that the system follows by default.

Whether I need to put a custom client side script or  custom server side script for the same. 



Note:

 

If you are posting an issue,

  1. We should be able to replicate it at our end. So please give us as much information as you can. Please see it from the point of view of the person receiving the communication.
  2. Paste your code at http://pastebin.com or http://gist.github.com and send only the URL via email
  3. For sending images, use http://imgur.com or other similar services. Do not send images as attachments. Links are good. Same goes for any file you are going to send.

     

    End of Note



    You received this message because you are subscribed to the Google Groups “ERPNext Developer Forum” group.

    To unsubscribe from this group and stop receiving emails from it, send an email to erpnext-developer-forum+un…@googlegroups.com.

    To view this discussion on the web visit https://groups.google.com/d/msgid/erpnext-developer-forum/dfaa8019-b67a-401a-bf7d-ef1f520425d4%40googlegroups.com.

    For more options, visit https://groups.google.com/d/optout.



Note:

 

If you are posting an issue,

  1. We should be able to replicate it at our end. So please give us as much information as you can. Please see it from the point of view of the person receiving the communication.
  2. Paste your code at http://pastebin.com or http://gist.github.com and send only the URL via email
  3. For sending images, use http://imgur.com or other similar services. Do not send images as attachments. Links are good. Same goes for any file you are going to send.

     

    End of Note



    You received this message because you are subscribed to the Google Groups “ERPNext Developer Forum” group.

    To unsubscribe from this group and stop receiving emails from it, send an email to erpnext-developer-forum+un…@googlegroups.com.

    To view this discussion on the web visit https://groups.google.com/d/msgid/erpnext-developer-forum/5D432740-C7CE-4D9F-839F-018528D6F487%40gmail.com.

    For more options, visit https://groups.google.com/d/optout.
Thanks Rushabh for the information. I would wait for v4.

I hope we would see the light of v4 soon......

On Thursday, May 29, 2014 12:00:12 PM UTC+5:30, rushabh wrote:
Aditya,

In version 4 there is a Sort By and Sort Field setting you can do via Customize Form view.


@rushabh_mehta

On 29-May-2014, at 11:56 am, Aditya Duggal <ad...@gmail.com> wrote:

Hi,

I would like to know if it is possible to sort the results of a link field ALPHABETICALLY instead of by the last edited sorting that the system follows by default.

Whether I need to put a custom client side script or  custom server side script for the same. 



Note:

 

If you are posting an issue,

  1. We should be able to replicate it at our end. So please give us as much information as you can. Please see it from the point of view of the person receiving the communication.
  2. Paste your code at http://pastebin.com or http://gist.github.com and send only the URL via email
  3. For sending images, use http://imgur.com or other similar services. Do not send images as attachments. Links are good. Same goes for any file you are going to send.

     

    End of Note



    You received this message because you are subscribed to the Google Groups “ERPNext Developer Forum” group.

    To unsubscribe from this group and stop receiving emails from it, send an email to erpnext-developer-forum+un…@googlegroups.com.

    To view this discussion on the web visit https://groups.google.com/d/msgid/erpnext-developer-forum/dfaa8019-b67a-401a-bf7d-ef1f520425d4%40googlegroups.com.

    For more options, visit https://groups.google.com/d/optout.



Note:

 

If you are posting an issue,

  1. We should be able to replicate it at our end. So please give us as much information as you can. Please see it from the point of view of the person receiving the communication.
  2. Paste your code at http://pastebin.com or http://gist.github.com and send only the URL via email
  3. For sending images, use http://imgur.com or other similar services. Do not send images as attachments. Links are good. Same goes for any file you are going to send.

     

    End of Note



    You received this message because you are subscribed to the Google Groups “ERPNext Developer Forum” group.

    To unsubscribe from this group and stop receiving emails from it, send an email to erpnext-developer-forum+un…@googlegroups.com.

    To view this discussion on the web visit https://groups.google.com/d/msgid/erpnext-developer-forum/22de253e-60c8-4113-90b2-9a44c9221fc4%40googlegroups.com.

    For more options, visit https://groups.google.com/d/optout.
Few more days. It will be worth the wait :)



@rushabh_mehta

On 29-May-2014, at 12:07 pm, Aditya Duggal <ad...@gmail.com> wrote:

Thanks Rushabh for the information. I would wait for v4.

I hope we would see the light of v4 soon......

On Thursday, May 29, 2014 12:00:12 PM UTC+5:30, rushabh wrote:
Aditya,

In version 4 there is a Sort By and Sort Field setting you can do via Customize Form view.


@rushabh_mehta

On 29-May-2014, at 11:56 am, Aditya Duggal <ad...@gmail.com> wrote:

Hi,

I would like to know if it is possible to sort the results of a link field ALPHABETICALLY instead of by the last edited sorting that the system follows by default.

Whether I need to put a custom client side script or  custom server side script for the same. 



Note:

 

If you are posting an issue,

  1. We should be able to replicate it at our end. So please give us as much information as you can. Please see it from the point of view of the person receiving the communication.
  2. Paste your code at http://pastebin.com or http://gist.github.com and send only the URL via email
  3. For sending images, use http://imgur.com or other similar services. Do not send images as attachments. Links are good. Same goes for any file you are going to send.

     

    End of Note



    You received this message because you are subscribed to the Google Groups “ERPNext Developer Forum” group.

    To unsubscribe from this group and stop receiving emails from it, send an email to erpnext-developer-forum+un…@googlegroups.com.

    To view this discussion on the web visit https://groups.google.com/d/msgid/erpnext-developer-forum/dfaa8019-b67a-401a-bf7d-ef1f520425d4%40googlegroups.com.

    For more options, visit https://groups.google.com/d/optout.




Note:

 

If you are posting an issue,

  1. We should be able to replicate it at our end. So please give us as much information as you can. Please see it from the point of view of the person receiving the communication.
  2. Paste your code at http://pastebin.com or http://gist.github.com and send only the URL via email
  3. For sending images, use http://imgur.com or other similar services. Do not send images as attachments. Links are good. Same goes for any file you are going to send.

     

    End of Note



    You received this message because you are subscribed to the Google Groups “ERPNext Developer Forum” group.

    To unsubscribe from this group and stop receiving emails from it, send an email to erpnext-developer-forum+un…@googlegroups.com.

    To view this discussion on the web visit https://groups.google.com/d/msgid/erpnext-developer-forum/22de253e-60c8-4113-90b2-9a44c9221fc4%40googlegroups.com.

    For more options, visit https://groups.google.com/d/optout.



Note:

 

If you are posting an issue,

  1. We should be able to replicate it at our end. So please give us as much information as you can. Please see it from the point of view of the person receiving the communication.
  2. Paste your code at http://pastebin.com or http://gist.github.com and send only the URL via email
  3. For sending images, use http://imgur.com or other similar services. Do not send images as attachments. Links are good. Same goes for any file you are going to send.

     

    End of Note



    You received this message because you are subscribed to the Google Groups “ERPNext Developer Forum” group.

    To unsubscribe from this group and stop receiving emails from it, send an email to erpnext-developer-forum+un…@googlegroups.com.

    To view this discussion on the web visit https://groups.google.com/d/msgid/erpnext-developer-forum/AA585FF1-32B7-43AF-841F-DC760A414AD5%40gmail.com.

    For more options, visit https://groups.google.com/d/optout.

Sort Field and Sort Order are used to determine how to sort the records in the list view when displaying it and it is not related to the link field.
I am really looking for a method to sort the values of the link field alphabetically (from A to Z or from Z to A). For example, when I click on item code, I need to see the codes of the item arranged ascending from A to Z (Aword1, Bword2, Cword3, … etc). How to achieve this?

Regards
Bilal

@bghayad Did you ever solve this problem? I’m running into the same thing.

As settings, I did not find.
And I did not continue working on this issue.
But as coding (customization): have you tried set_query if it possible to take the ordering as argument? I think this need to be checked or ask on the forum about it.
If set_query resolved your problem, please let me know.

Regards
Bilal

I have the same problem. I don’t really know how to fix this. All linked fileds seems to be sorted randomly. Is there any solution out of the box? Or script? But it affects all linked field so to script this will be a lot of work :slight_smile:

Have you tried something like this: (include in onload trigger, example works on tiem_code field)

cur_frm.fields_dict['item_code'].get_query = function(doc, cdt, cdn) {
     return {
         filters:{'default_supplier': doc.supplier},
         order_by: 'default_supplier'
     }
}

thank you, but what I like is to sort the field based on itself. I tried your code on timesheet, just to sort employees, but this doesn’t work :frowning:

frappe.ui.form.on("Timesheet", "onload", function(frm) {
cur_frm.fields_dict['employee'].get_query = function(doc, cdt, cdn) {
     return {
         filters:{'employee': doc.employee},
         order_by: 'employee_name'
     }
}
});

First of all, as there is no query will be done, so you need to use set_query and not get_query.
Second: I do not think you need to use filters because you are not filtering, but rather you are ordering.
Third: you need to check (we need someone to confirm) if it is possible to use order_by as in below example:

frappe.ui.form.on(“Timesheet”, “onload”, function(frm) {
frm.set_query(“employee”, function(doc) {
return {
order_by: ‘employee_name’
};
});
}

Regars
Bilal

Any luck on this? I’d like to sort by size field when selecting the item from the sales order item table and trying to figure out how to do this.

What do you mean by size field? Do you mean the number of characters of the item name or what exactly?

Regards
Bilal