Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    Formula

    Hi,

    I am trying to work on formula. Why case 1 is working, but case 2 is not working? Am I implementing it incorrectly?

    case 1:
    Code:
    isc.RestDataSource.create({
          ID: "DS1",
          clientOnly: true,
          fields: [
            { name: "Item", type: "text" },
            { name: "Quantity", type: "integer" },
            { name: "UnitPrice", type: "float" },
            { name: "TotalAmount", type: "float" }
          ],
          cacheData: [
            {
              Item: "Item A",
              Quantity: 1,
              UnitPrice: 1.45,
              TotalAmount: 1.0
            },
            {
              Item: "Item B",
              Quantity: 2,
              UnitPrice: 2.2,
              TotalAmount: 4.0
            },
            {
              Item: "Item C",
              Quantity: 3,
              UnitPrice: 1.9,
              TotalAmount: 3
            }
          ]
        });
        isc.ListGrid.create({
          ID: "Grid",
          height: 400,
          width: 400,
          dataSource: "DS1",
          canEdit: true,
          autoSaveEdits: false,
          modalEditing: true,
          autoFetchData: true,
          fields: [
            {
              name: "Item",
              type: "text"
            },
            { name: "Quantity", type: "integer" },
            {
              name: "UnitPrice",
              type: "float",
              format: "#.#0",
              editorFormula: {
               text: "toFixed(UnitPrice, 2)"
              }
            },
            {
              name: "TotalAmount",
              type: "text",
              editorFormula: {
                text: "toFixed(UnitPrice * Quantity, 2)"
              }
            }
          ]
        });
        isc.VLayout.create({
          ID: "Layout",
          height: "100%",
          width: "100%",
          autoDraw: true,
          members: ["Grid"]
        });
    case 2:
    Code:
    isc.RestDataSource.create({
          ID: "DS1",
          clientOnly: true,
          fields: [
            { name: "Item", type: "text" },
            { name: "Quantity", type: "integer" },
            { name: "UnitPrice", type: "float" },
            { name: "TotalAmount", type: "float" }
          ],
          cacheData: [
            {
              Item: "Item A",
              Quantity: 1,
              UnitPrice: 1.45,
              TotalAmount: 1.0
            },
            {
              Item: "Item B",
              Quantity: 2,
              UnitPrice: 2.2,
              TotalAmount: 4.0
            },
            {
              Item: "Item C",
              Quantity: 3,
              UnitPrice: 1.9,
              TotalAmount: 3
            }
          ]
        });
        isc.ListGrid.create({
          ID: "Grid",
          height: 400,
          width: 400,
          dataSource: "DS1",
          canEdit: true,
          autoSaveEdits: false,
          modalEditing: true,
          autoFetchData: true,
          fields: [
            {
              name: "Item",
              type: "text"
            },
            { name: "Quantity", type: "integer" },
            {
              name: "UnitPrice",
              type: "float",
              format: "#.#0"
            },
            {
              name: "TotalAmount",
              type: "text",
              editorFormula: {
                text: "toFixed(UnitPrice * Quantity, 2)"
              }
            }
          ]
        });
        isc.VLayout.create({
          ID: "Layout",
          height: "100%",
          width: "100%",
          autoDraw: true,
          members: ["Grid"]
        });
    Regards,
    Ryan
    Last edited by ryanang; 2 Sep 2020, 18:27.

    #2
    You have not indicated what product or version you are using, and not indicated that you've tried the latest patched version. This is always required when reporting issues.

    Second problem: you have not explained what the problem is: explain what you expect and what is happening (after testing in the latest patched version).

    Third problem: please do not expect people to closely analyze your code to figure out what the difference is. Tell us what the difference is between the two versions, as you perceive it.

    Comment


      #3
      Sorry.

      I am using v12.0p_2019-01-05. I try to calculate total amount using formula like I saw in this example https://www.smartclient.com/smartcli...dEditorFormula

      I don't know why TotalAmount will auto calculate only when I add editorFormula in UnitPrice (Please refer to case 1), when I remove editorFormula from UnitPrice field, TotalAmount is not calculate. (Please refer to case 2)

      I tried my sample code on v12.1p_2020-09-01 only case 1 working. Am I missing something?

      Regards,
      Ryan

      Comment


        #4
        Any update on this?

        Comment

        Working...
        X