editor.dependent val pulling from rendered data, and not actual data

editor.dependent val pulling from rendered data, and not actual data

dan@19ideas.comdan@19ideas.com Posts: 56Questions: 13Answers: 1

I add a render function to each data in the datatables plugin:

        {
          data: 'ColumnA',
          render: function (data, type, row, meta) {
            return MathService.Rounding(data, 1);
          }
        },

For example, my data is 4.356532, and what's being rendered from MathService.Rounding() is shown as 4.4

When I hit my dependent field:

  _editor.dependent('ColumnA', function (val, data, callback) {

  }

val is pulling 4.4, not 4.356532.

I think that's an error, because render is not data.. it's supposed to be a presentation function, correct? If I look at the data parameter, it shows all the values as the original form, before the render. So I'm wondering, how can I prevent this?

This question has an accepted answers - jump to answer

Answers

  • dan@19ideas.comdan@19ideas.com Posts: 56Questions: 13Answers: 1

    I realize this is a bit confusing, because "val" parameter is the number that I enter when editing a field.. but the scenario I'm bringing up is when I open click the "edit" button to open up the form for the row I selected.

    All dependent functions gets called when you try to edit a row on the datatable, no matter what.

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    Answer ✓

    I think that's an error, because render is not data.. it's supposed to be a presentation function, correct?

    Correct! It absolutely should be giving you the original value.

    Could you give me a link to a page showing the issue so I can check it out please?

    Thanks,
    Allan

  • dan@19ideas.comdan@19ideas.com Posts: 56Questions: 13Answers: 1

    I wish I could make an example of this issue, but it only exists on my localhost, so I really need to create a workaround. If I could prevent a dependent field from running every time I open an editor and have it only change when I enter in a value for that field, that'd work.

    Isn't there some kind of demo-playground that has access to all the libraries with initial data, so I can just copy and paste some code in, in order to get something to show?

    I tried doing flags by copying values from previous entries and comparing it to newer entries.. but because of the above issue of rounding, it doesn't work. The only way it would work is if I round the original value, but this breaks other things.

  • dan@19ideas.comdan@19ideas.com Posts: 56Questions: 13Answers: 1

    Argh.. false alarm!

    I saw code in the editor:

          {
            label: "ColumnA",
            name: "ColumnA",
            data: function (data, type, set) {
              return MathService.Rounding(data.ColumnA, 1);
            }
    

    Wow.. I think this code was entered to mimic the rendering in the datatables, but in actuality it replaced the data. My apologies!

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin

    That'd do it! Using field.data as a function in Editor, while possible, is something I discourage (it isn't documented) since you need to consider the type === 'set' case as well (i.e. the API setting a value).

    Allan

This discussion has been closed.