Skip to main content
Nintex Community Menu Bar
Question

Javascript that runs when selected rows changes


Forum|alt.badge.img+6

Is it possible to run a javascript snippet everytime a selection is made on a table? I’d like to throw a warning message up for my users when they select an Opportunity that one of our mass actions won’t work on.

Translate
Did this topic help you find an answer to your question?

4 replies

Forum|alt.badge.img+4

Hey Jerry,

My first instinct would be to subscribe to a skuid.event. However I don’t believe one exists for merely selecting a row in a table.

A few questions that may unveil an alternative for you.

1) Why do some of the rows not work in your mass actions?
2) Which field on the row will tell you that it doesn’t work?

Translate

Forum|alt.badge.img+6
  • Author
  • 56 replies
  • July 10, 2024

You’d be correct, One of my colleagues also suggested subscription as an option, but there is no ability to get the checkbox checked actions. I am currently proceeding with simply aborting the mass action and giving the users a message displaying the error encountered. 

Translate

Forum|alt.badge.img+10

Jerry, it is possible to fire an action off of a checked or unchecked event with some very hacky javascript.

You can use mutation observers on the table to attach the functions each time the table is rendered. You can probably make this work as an inline resource, but for my use, I used an inline snippet since I knew each and every place that would cause the table to rerender.

So there are three things going into this.

  1. An invisible id column hidden with CSS for your use once you’ve established whether or not the column has been checked/unchecked
  2. Mutation Observer to check if html table has been added/modified to ensure your custom functions are always present even if the table gets rerendered.
  3. Custom functions on click and unclick of the checkboxes



Mutation observer snippet

var $ = skuid.$; var attachCustomFunctionToCheckBoxes = skuid.snippet.getSnippet('attachCustomFunctionToCheckBoxes'); var observer = new MutationObserver(function(mutations, observer) { // fired when a mutation occurs attachCustomFunctionToCheckBoxes(); }); // define what element should be observed by the observer // and what types of mutations trigger the callback //#sk-1if7S8-779 is your tableOd observer.observe($("#sk-1if7S8-779")[0], { subtree : true, childList : true }); 







Custom Functions on checkbox snippet

var $ = skuid&#46;$; &#47;&#47;this function attaches check all and uncheck all functionionality to the checkbox that checks and unchecks all row checkboxes&#46; &#47;&#47;This is needed since if checked/unchecked without attaching this function,function for individual checkbox rows won't be triggered (probably because skuid subscubries to internal events that we can't see) $("#sk-1if7S8-779")&#46;find('&#46;checkcolumn')&#46;find('input:checkBox')&#46;off()&#46;change( function(){ if ($(this)&#46;is(':checked')) { &#47;&#47;check all with jquery in order to trigger custom events $("#sk-1if7S8-779")&#46;find("td")&#46;find("input:checkbox")&#46;prop('checked',true)&#46;change(); } else{ &#47;&#47;uncheck all with jquery in order to trigger custom events $("#sk-1if7S8-779")&#46;find("td")&#46;find("input:checkbox")&#46;prop('checked',false)&#46;change(); } }); &#47;&#47;attach add/remove id function to checkbox rows $("#sk-1if7S8-779")&#46;find("td")&#46;find("input:checkbox")&#46;off()&#46;change( function(){ row = this; &#47;&#47;get id from hidden column (my id starts with 'a1c') rowId = $("&#46;nx-item")&#46;has(row)&#46;children()&#46;filter(function(){return this&#46;innerText&#46;includes('a1c')})[0]&#46;innerText; if ($(this)&#46;is(':checked')) { &#47;&#47;customCheckedRowFunction(rowId); } else{ &#47;&#47;customUncheckedRowFunction(rowId); } });<br />

 

Translate

Forum|alt.badge.img+10

Something of note that changed in brooklyn release is that return characters are added in the table data. If you need to remove those do:

tableData = tableData.replace(/(
|
|
)/gm,"");
Translate

Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie Settings