Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3938162
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T00:09:09+00:00 2026-05-20T00:09:09+00:00

I have a javascript array that I am using as a data source in

  • 0

I have a javascript array that I am using as a data source in an editable YUI datatable:

var data = [
    { Col1: "one", Col2: 1 },  
    { Col1: "two", Col2: 2 },      
    { Col1: "three", Col2: 3 },
    { Col1: "four", Col2: 4 }
];
var customFormatter = function (elLiner, oRecord, oColumn, oData) {
    elLiner.innerHTML = "Click me";
    $(elLiner).click(function () {
        var rsvalue = oRecord.getData("Col1");
        var datavalue = data[oRecord.getCount()].Col1;;
        alert("rs:" + rsvalue + ", data:" + datavalue);
    });
};
var coldefs = [
    { key: "Col1", editor: new YAHOO.widget.TextboxCellEditor() },
    { key: "Col2" },
    { key: "Col3", formatter: customFormatter }
];
var datasource = new YAHOO.util.DataSource(data);
datasource.responseType = YAHOO.util.DataSource.TYPE_JSARRAY;
datasource.responseSchema = { fields: [ "Col1", "Col2" ] };
var datatable = new YAHOO.widget.DataTable("mytable", coldefs, datasource);
datatable.subscribe("cellClickEvent", datatable.onEventShowCellEditor);

When I change a value in the editable cells, I see that the datatable’s Record gets updated with the new value, but the underlying data array does not. I would like to work with this javascript array (or another one of this shape) when the user is finished editing the data, where I need to do some post-processing and send it off to the server. In the generally good YUI examples, I don’t see that they ever try to reconcile changes made within a datatable to the underlying data source. Does an example like this exist? What is the best way for me to push my changes back into my data array?

Here’s a jsfiddle with my little test: http://jsfiddle.net/cfarmerga/uArKs/1/

Should I just catch the editorSaveEvents for the DataTable and just walk the recordset and update my javascript array?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T00:09:10+00:00Added an answer on May 20, 2026 at 12:09 am

    If possible, I would suggest rebuilding the array of data once after the user has finished editing, do any post processing, and then send it off to the server. This would be more efficient then trying to keep the datasource and the array in sync after every individual edit. To rebuild the array, you can loop through the datatable’s RecordSet.

    var rs = datatable.getRecordSet(),
        len = rs.getLength(),
        data = [];
    
    for (var index=0; index < len; index++) {
        data.push(rs.getRecord(index).getData());
    }
    

    Note that getData() returns an object representing the entire record. You could also pass individual keys to getData() (such as getData(“Col1”)) to get individual fields of the record.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using Javascript I want to have a JSON or array that will store id
I have these array in javascript that is going to be the input data
I am using jQuery 1.7.1 (but that's probably irrelevant). I have several JavaScript arrays
I am currently trying to pass an array that I have created in Javascript
I have a Knockout observable array that I wish to edit from within Javascript
I have an array in javascript that I need to join and send through
I have a variable length array of strings declared in javascript that contains Dungeons
I have this array, that I want to parse into javascript. $offerText[] = (
I have some Javascript code that creates 2 arrays: One for Product Category and
I have a javascript array: var exclude = [Santorum,Obama,Romney,Gingrich]; I have html links: <a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.