Trigger custom component on data model update

  • 1
  • Question
  • Updated 4 years ago
  • Answered

Is there a better way to get my custom component to fire when a data model is updated?  Right now we are listening for changes on the DOM -  like when the save button is pressed:


$('#myTableComponent .nx-actionselect .nx-actionselect-text').bind('DOMSubtreeModified', function() {
        certChart.init();
    });
Photo of Peter Herzog

Peter Herzog

  • 1,664 Points 1k badge 2x thumb
  • confident

Posted 4 years ago

  • 1
Photo of Zach McElrath

Zach McElrath, Employee

  • 49,056 Points 20k badge 2x thumb
Use Model Actions to either run a Snippet or Publish an Event that runs your Component init logic. The Model Actions allow you to bind to specific Model events and then run any action in the Action Framework. So for instance in the screenshot below, we are setting the "Initiating Event(s)" such that whenever any row in the Account Model's "Name" field is updated, we will run a set of Actions. The Actions we're going to run, as the 2nd screenshot shows, is "Publish Event". We will publish a custom event, e.g. "certChart:init". Then in your code, you just need to subscribe to that event, as in the code sample below:





skuid.events.subscribe('certChart:init',function(){
   certChart.init();
});

For more information on the Skuid Events framework, read the docs.
(Edited)