I am using the datatables from YUI 2.8.2 and its widgets to edit a datasource (YAHOO.example.Data.response) as follows:
this.bpDataSource = new YAHOO.util.DataSource(YAHOO.example.Data.response);
response_datasource = this.bpDataSource;
this.bpDataSource.responseType = YAHOO.util.DataSource.TYPE_JSON;
this.bpDataSource.responseSchema = {
resultsList: "item_evaluacion",
fields: [ ... ]
};
this.standardSelectDataTable = new YAHOO.widget.ScrollingDataTable("div_item",
bpColumnas, this.bpDataSource, {height:"9em"} );
I want to retrieve the edited data from this datatable and proccess it. I tried a variable pointing to this.bpDataSource first but this variable contains only the original datasource without the changes the user made.
How can I retrieve the updated version of my datasource?
The DataSource only retrieves the data but does not keep a reference to the data retrieved. Once it has passed the retrieved data to whatever requested it, in this case DataTable, it forgets about it. DataTable then keeps the data in the RecordSet collection, which is composed of individual Record instances where you can fetch the values by field name. For some funny reason, the API docs for both Record and RecordSet are not under DataTable. I know the docs for those two are somewhere in there, but they somehow got filed under some other component.
Anyway, in DataTable, you have method getRecord() which takes an index. You can loop through it until it returns null or undefined. Otherwise, I believe you could do getRecordset().getLength() and use that to iterate with a for loop. Then, on each record instance, method getData() takes the column key and returns the value.
For more information read the two 'Working with the DataTable widget' articles referenced in the heading of DataTable.
Related
I'm currently using BreezeJs in an asp.net web application and identified that 'HttpResponse.Data' and the 'results' attribute values of executed breeze query are different in random cases.
The identified scenario: when the database is manually updated using a stored-procedure and set several data records values to empty.
return EntityQuery.from('SampleEndpointName')
.withParameters({ Id: sampleId})
.using(self.manager)
.execute()
.then(querySucceeded, this._queryFailed);
function querySucceeded(data) {
var sampleData;
if (data.results.length > 0) {
sampleData = data.results;
}
return sampleData;
In above-mentioned scenario, a network call triggers and fetch the correct values but not updates 'results' of returned breeze object. The 'results' retain previous values. Tried adding .using(MergeStrategy.OverwriteChanges); but didn't work. Any clues on fixing this issue?
I'm using ionic's events to pass data from page to page. In this instance I'm passing an array to another page, let's say with two objects. The data I'm wanting to add to is called dataOne and I'm using a life cycle function so that when the user enters the page they will be automatically tested from this function whether or not there is an event to be concatenated onto dataOne. The issue is, the data isn't being added. I'm able to retrieve the data but nothing happens to the table, as I'm still getting the same result.
ts
ionViewWillEnter(){
this.events.subscribe('market', (dataTwo) => {
return this.dataOne = this.dataOne.concat(dataTwo)
})
}
What is 'Market' ? dataOne is array? In my opinion,
dataOne: any[]=[];
...
this.events.subscribe((dataTwo) =>{
this.dataOne.push(dataTwo.market); // if market you want to catch data
}
In the Kendo UI documentation for the DataSource component, it states that the data function is used to get data items for the data source.
However it also states that if the data source is bound to a JavaScript array (via the data option) the data method will return the items of that array. Every item from the array is wrapped in a kendo.data.ObservableObject or kendo.data.Model.
How can I retrieve the original unwrapped data items (i.e. having same reference) that were passed into the data source?
I ask because I'm using a Kendo UI treeview control and in its event handlers (e.g. check event) I want to update the original data item for a tree node based on some custom logic.
Update
For example here is a simple treeview having a single node (of course in a realistic scenario the tree would contain many nodes) . When checking the node I want to get a reference to the original data item for the checked node. this.dataItem(e.node) does not return the original data item as the log statement outputs false.
<div id="treeview"></div>
<script>
var mydata = [
{ text: "foo", checked: false}
];
$("#treeview").kendoTreeView({
checkboxes: true,
dataSource: mydata,
check: function(e) {
console.log(this.dataItem(e.node) == mydata[0]); //I want this to output true
}
});
</script>
If I understand your question correctly, you can get to the records independently by referencing your data source and using the .at(x) function, where x equals whatever record of your data source you are attempting to access. So to get the first.
var theData = yourDataSource.at(0);
To update it, you then use .set and .sync.
theData.set('userFirstName', 'Joe');
theData.set('userAverageTime', 10);
yourDataSource.sync();
Using .set() is handy because if you store all your updates into an iterable collection, then you can just run through them.
$.each(updatedVars, function(key, element) {
theData.set(key, element);
});
yourDataSource.sync();
I have a Sinatra app which loads information from an external API and displays it on a page. This is done in Sinatra which gets the information and puts it a temporary model instance (which is NOT saved), so it is easier to access all its propertys in the view.
Now when the user clicks a link I want the model instance to be saved to the database, which I think only can be done via AJAX etc. because the last request already finished and none of the instances is still alive. I thought I needed to extract all the information of the corresponding HTML elements and make an AJAX-Post to another route.
My problem is now, I want to be able to create(and save) the model using #model = Model.create(params[:model]). It would be clear what to do using a form, but that is not an option because all the data is displayed within a table and each table row is one instance of the model.
How do I serialize the data from the table row in which the clicked link is, so I can use it as described above?
UPDATE
I am using MULTIPLE instances of the object class, each in one tablerow!
I am using DataMapper, only the temporary objects are not stored!
I dont want to clutter up my whole setup!
Did you consider ActiveResource? You can use ActiveResource to maintain object state. If your REST API follows convention it would be very easy to map resource.
Regarding second half sending back data to your controller, you could store in hidden variable(s) and on post it should be easy to construct back the object and persist it to database.
Something like
#model
class MyModel < ActiveResource::Base
# set configs here
end
# To fetch record from REST API in controller or whatever
MyModel.find(1)
#in controller on form submit or AJAX
post "/path" do
MyModel.new(params[:myModel])
end
Update
To maintain state of object without using hidden form
in javascript you can have something like
var myModel = #{myModel.to_json}; #Ruby interpolation in HAML it will depend on templating language
on certain action you can update the JSON object
and to post using AJAX
$.post("post/path", myModel);
More Update
In External JS
function my_js_function(obj) {
/* do something useful here like setting up object hash etc
*/
}
In Ruby Template
<script>
var myObj = #{myObj.json}
my_js_function(myObj);
</script>
I found a pretty easy solution. It was nothing more than getting all the required values from the DOM and putting them into an Array!
application.js:
$(".enable").click(function() {
var table_row = $(this).closest("tr");
var model_array = new Array;
var elements_with_information = jRow.find("[name]");
elements_with_information.each(function() {
// Doing some checking on which kind of element
// it actually is and then basically doing:
model_array.push($(this).text());
});
// Constructing nested array to use `params[:model]`
var data = { "model" : {
"property1": model_array[0],
"property2": model_array[1]
}};
// Now doing the AJAX request
$.ajax({
url: "/model/doshit",
type: "POST",
data: data
});
});
It is possible to use the getRowData method to retrieve the current of a cell but this retrieves the current cell content rather than the original data before it went through the formatter.
How do I retrieve the original content before the formatting transformations are applied? FYI I am populating the table using JSON.
I had to dig through the documentation a bit to come up with the solution, to see it in its original context go here: jqGrid Data Manipulation, specifially the section near the end titled "User Data".
First, modify your jsonReader implementation as follows:
jsonReader: {
root: 'Data',
page: 'Page',
total: 'Total',
records: 'Records',
userdata : 'Data',
repeatitems: false,
id: 'Id'
}
Note the userdata option set to the same as root 'Data'
In my case I needed to retrieve the original row data when the user selected a row. I implemented this as follows:
onSelectRow: function(rowid) {
processRow(rowid);
}
To retrieve the data within the process row method I have the following:
var rowData = $("#resultGrid").getGridParam('userData')[rowId - 1];
Where #resultGrid is a reference to my jqGrid.
This will then return the original data bound to that row before any formatting was applied.
A couple of points to note:
In my case the grid is paged so the result set is never greater than 10 items therefore the 'userdata' wont grow too large
Sorting is performed server side so that index rowId will always return the correct value from 'userData'
While 'userdata' as referenced as an option on jsonReader is all lower case, to retrieve it using getGridParam you need to reference it as 'userData'
This is how to retrieve cell data from a row.
var rowData = jQuery(this).getRowData(rowId);
var colData = rowData['columnName']);
columnName is table's column name.