Can someone explain dmx.Formatters? and provide some reference on how to use it?

Hey,

I just came accross dmx.formatters in the forums and am surprisede its taken be a year to realise this feature exists :slight_smile: I use dmx.parse and dmx.global.set quite a bit, but would love to explore what the custom formatters is all about and unlock more potential.

It seems it pops up as a solution to a number of specific queries, but i can’t find any information on its general usage, ints syntax, what exact formatters you can use in it (I’ve seen string and array etc)

Would someone care to give a general overview on these points? Is it covered somewhere i’ve missed, perhaps one of the dmx-zone blogs?

Anyway…any general info would be great as i’m sure i could make use of it,

Here’s an example from one of the posts…

dmx.Formatters('string', {
  getWeek: function(val) {
    return moment(val).week();
  },
  getIsoWeek: function(val) {
    return moment(val).isoweek();
  }
});

Cheers!

These are similar to the server side formatters.
You should define these client side formatters in jQuery document ready function ideally.

I am unable to find many example posts right now. But there are many in the community.
4 I could find:




The syntax in example you have posted is something I have seen for the first time.
The syntax I have used most is as in link… with 3 parameters…

  1. Source Object Type
  2. Custom Formatter Name
  3. Function with Custom Parameters

These formatter, just like server side do not show up in the UI. You can use them in code view.
Server side formatter can now show up in the UI with the new #custom-modules, but no similar option is available for client side yet.

Hope this help a bit.

1 Like

Functions defined inside objects.

It helps reading and maintaining a group of functions. In this case those formatters that affect a string.

In ES6 you can even bypass using function

dmx.Formatters('string', {
  getWeek(val) {
    return moment(val).week();
  },
  getIsoWeek(val) {
    return moment(val).isoweek();
  }
});
2 Likes