DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Newsletter
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Related

  • DZone Community Awards 2022
  • An Introduction to Type Safety in JavaScript With Prisma
  • A Practical Pipeline for Identifying Sensitive Columns Before Test Data Masking
  • Parquet vs Lance: How Storage Layout Changes the Read Path

Trending

  • Microsoft Foundry Agent Debugging Dashboard with Microsoft Fabric Eventhouse, KQL, Docker and Grafana
  • The Five Stages of AI Adoption: A Practical Maturity Model for Software Teams
  • Designing Memory Architecture for Stateful AI Agents: Short-Term Context and Long-Term Persistence
  • Stop Writing Database Migration Scripts: Declarative Schema Sync for Java

Draft This article hasn't been published, so readers can't see it.

In moderation This article is waiting for review, so readers can't see it yet.

Deleted This article has been deleted, so readers can't see it.

  1. DZone
  2. Data Engineering
  3. Data
  4. Working With ArrayDataProviders Using JavaScript Functions in Visual Builder

Working With ArrayDataProviders Using JavaScript Functions in Visual Builder

Learn how to add additional processing/updates on all the records you're storing in an ADP.

By 
Shay Shmeltzer
·
May. 14, 19 · Tutorial
Post on X (opens in a new tab) Share on LinkedIn (opens in a new tab)
15.2K Views

Join the DZone community Save articles, join the discussion, and download Refcards and Trend Reports with a free account.

Join for free Already a member? Log in

Storing data in ArrayDataProviders (rather than SDP) is useful whenever you want to further modify the data on the client side — for example, if you are looking to create updatable tables in your UI. A common follow up question is, "how can I do additional processing/updates on all the records I'm storing in the ADP?" This is what this post is about.

Since the records are now stored on the client-side, you can access them through JavaScript. You can, for example, write a page level module function to loop over the set of records and modify them. For example, in the video below I'm using this little function to raise the salary of all the employees:

PageModule.prototype.arrayModifier = function(array){
  console.log(array.length + " is what we got")
    for (var i = 0; i < array.length  ; i++ ) {
      array[i].salary = array[i].salary+2;
      console.log("salary after " + array[i].salary);
  }
  return array;
}

Into this function you'll pass the array of data from the ArrayDataProvider — you can do this in the parameter mapping of the function pointing to the data object like this:

Data array
Data Array

Once your function finished its processing of the data, you'll want to update the ArrayDataProvider back to reflect the changes you made. To do this you can use the action called "Fire Data Provider Event." This function has the option to mutate events (update, insert, delete). You can read the doc about this and other actions parameters here. For the update, you simply need to provide the array of updated data like this:

Updated Data
Updated Data

That's it. You can see all the pieces of this process working together in the video below:


Database JavaScript Data (computing)

Published at DZone with permission of Shay Shmeltzer. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • DZone Community Awards 2022
  • An Introduction to Type Safety in JavaScript With Prisma
  • A Practical Pipeline for Identifying Sensitive Columns Before Test Data Masking
  • Parquet vs Lance: How Storage Layout Changes the Read Path

Partner Resources

×

Comments

Loading comments

The comments didn't load

Please try again in a moment.

Likes

Loading

The next likes didn't load. Please try again.

The likes didn't load

Please try again in a moment.

See who liked this

Log in or join DZone for free to see who liked this article.

Log in Join for free
  • RSS
  • X
  • Facebook

ABOUT US

  • About DZone
  • Support and feedback
  • Community research

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 215
  • Nashville, TN 37211
  • [email protected]

Let's be friends:

  • RSS
  • X
  • Facebook