Announcement

Collapse
No announcement yet.

Calculated Field Order

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Calculated Field Order

    Hello,

    I have the following definition for a calculated field in my entity.

    registrationNumber is a varchar like : R1000, R1001 etc.
    siteNumber is a varchar like: 000, 001, 002, etc.

    Thus, the concatenated field would look like:

    R1000-000, R1000-001,R1000-002
    R1001-000, R1001-001, R1001-001 etc

    Based on codebase syntax, I assumed the "order" syntax below would properly allow me to order the list in list view. However, when I attempt to do so, it doesn't change the order.


    For example,

    If list View has:

    R1000-000,
    R1000-001,
    R1000-002

    And I sort using the drop down arrow to change to desc it still shows

    R1000-000,
    R1000-001,
    R1000-002​

    Expected output:

    R1000-002,
    R1000-001,
    R1000-000


    Am I missing somthing?




    Code:
     "registrationNumberSiteNumber": {
    "type": "varchar",
    "notStorable": true,
    "readOnly": true,
    "select": {
    "select": "CONCAT:(radiationMachineCertificate.registrationNumber,'-',siteNumber)",
    "leftJoins": [
    [
    "RadiationMachineCertificate",
    "radiationMachineCertificate",
    {
    "radiationMachineLocation.radiationMachineCertificateId:": "radiationMachineCertificate.id",
    "radiationMachineCertificate.deleted": false
    }
    ]
    ]
    },
    "order": {
    "order": [
    ["CONCAT:(radiationMachineCertificate.registrationNumber,'-',siteNumber)", "{direction}"]
    ],
    "leftJoins": [
    [
    "RadiationMachineCertificate",
    "radiationMachineCertificate",
    {
    "radiationMachineLocation.radiationMachineCertificateId:": "radiationMachineCertificate.id",
    "radiationMachineCertificate.deleted": false
    }
    ]
    ]
    }
    }
    },​
    Last edited by czcpf; 03-06-2024, 11:00 PM.

  • #2
    if both fields on the same entity why leftJoins ?

    Comment


    • czcpf
      czcpf commented
      Editing a comment
      Good point. Why would that matter for sorting issue though?

    • rabii
      rabii commented
      Editing a comment
      Not sure why but it could cause an issue, also note that you have an extra } in your file.

  • #3
    I found the issue. I had a custom orderer I defined called registrationNumberSiteNumber, which is the same as the field name in this case and so it was using the custom orderer class instead of the "order" definition from the field.

    Comment


    • #4
      For others, here is the full code which worked. I wanted to sort by registration number and then by site number. This does that. It also allows you to add this field to textFilterFields, which I also needed. This way, user can search by the concatenated field as well.

      Code:
      "registrationNumberSiteNumber": {
      "type": "varchar",
      "notStorable": true,
      "readOnly": true,
      "trim": true,
      "select": {
      "select": "CONCAT:(rmc.registrationNumber,'-',siteNumber)",
      "joins": [
      [
      "RadiationMachineCertificate",
      "rmc",
      {
      "radiationMachineLocation.radiationMachineCertificateId:": "rmc.id",
      "rmc.deleted": false
      }
      ]
      ]
      },
      "order": {
      "order": [
      ["rmc.registrationNumber","{direction}"],
      ["siteNumber","{direction}"]
      ],
      "joins": [
      [
      "RadiationMachineCertificate",
      "rmc",
      {
      "radiationMachineLocation.radiationMachineCertificateId:": "rmc.id",
      "rmc.deleted": false
      }
      ]
      ],
      "additionalSelect": ["rmc.registrationNumber","radiationMachineLocation.siteNumber"]
      },
      "where": {
      "LIKE": {
      "joins": [
      [
      "RadiationMachineCertificate",
      "rmc",
      {
      "radiationMachineLocation.radiationMachineCertificateId:": "rmc.id",
      "rmc.deleted": false
      }
      ]
      ],
      "whereClause": {
      "CONCAT:(rmc.registrationNumber,'-',siteNumber)*": "{value}"
      },
      "distinct": true
      },
      "NOT LIKE": {
      "joins": [
      [
      "RadiationMachineCertificate",
      "rmc",
      {
      "radiationMachineLocation.radiationMachineCertificateId:": "rmc.id",
      "rmc.deleted": false
      }
      ]
      ],
      "whereClause": {
      "CONCAT:(rmc.registrationNumber,'-',siteNumber)!*": "{value}"
      },
      "distinct": true
      },
      "=": {
      "joins": [
      [
      "RadiationMachineCertificate",
      "rmc",
      {
      "radiationMachineLocation.radiationMachineCertificateId:": "rmc.id",
      "rmc.deleted": false
      }
      ]
      ],
      "whereClause": {
      "CONCAT:(rmc.registrationNumber,'-',siteNumber)": "{value}"
      },
      "distinct": true
      },
      "<>": {
      "joins": [
      [
      "RadiationMachineCertificate",
      "rmc",
      {
      "radiationMachineLocation.radiationMachineCertificateId:": "rmc.id",
      "rmc.deleted": false
      }
      ]
      ],
      "whereClause": {
      "CONCAT:(rmc.registrationNumber,'-',siteNumber)!=": "{value}"
      },
      "distinct": true
      },
      "IS NULL": {
      "joins": [
      [
      "RadiationMachineCertificate",
      "rmc",
      {
      "radiationMachineLocation.radiationMachineCertificateId:": "rmc.id",
      "rmc.deleted": false
      }
      ]
      ],
      "whereClause": {
      "CONCAT:(rmc.registrationNumber,'-',siteNumber)=": null
      },
      "distinct": true
      },
      "IS NOT NULL": {
      "joins": [
      [
      "RadiationMachineCertificate",
      "rmc",
      {
      "radiationMachineLocation.radiationMachineCertificateId:": "rmc.id",
      "rmc.deleted": false
      }
      ]
      ],
      "whereClause": {
      "CONCAT:(rmc.registrationNumber,'-',siteNumber)!=": null
      },
      "distinct": true
      }
      }
      }​
      Last edited by czcpf; 03-08-2024, 08:15 PM.

      Comment

      Working...
      X