I have create a add record form in extjs which stores user entered data into grid.
Well , if found following method to get form values from formPanel
var formPanel = new Ext.form.FormPanel({...});
var form = formPanel.getForm();
var firstName = form.findField('firstname').getValue();
but i want to covert all the user input value into JSON and want to store into Grid panel and want to send it to the server also. but using findField i have to manually create the array and then need to encode it into JSON , so is there any alternate way to directly read values from form and convert it into JSON and store it into Grid Panel.
When you say "want to store in the GridPanel" would you be updating an existing record in the Grid's store or would you be inserting a new one or both? (depending on whether its add or update probably?)
For such situations, BasicForm (var form in your snippet above) provides updateRecord( Record record ) method.
So your steps would be -
var record = Record.create(...) // in case of insert
OR
var record = //obtain record from grid.getStore() in case of update
Then,
formPanel.getForm().updateRecord(record); //update the passed record with values from the form
Followed by committing the record back to the store-
grid.getStore().add(record); //in case of insert
grid.getStore().commitChanges(); //incase of update
Reference - Ext.form.BasicForm , Ext.data.Record
Define your record type -
MyRecordType = Ext.data.Record.create(['id', 'field1', 'field2']);
var myrec = new MyrecordType();
Now pass myrec to updateRecord as mentioned above.
Related
I have an Add-on I'm updating for Sheets. I want to store information each time the user runs one of two functions, so I've created a function to push than info to Document Properties. Ultimately I want to send that data to a sheet at my end once a certain number of values have been collected.
The problem I'm having is that when I run a test function to Log the data contained, it only shows me the most recent data; I'm not sure I'm adding to existing data or replacing it. The data pairs should include the user's email address and the name of the sheets tab created by one of two functions that call this storeStats function.
In short:
*Do I need to declare the name of the Property Store before adding data to it?
*How do I add more data without deleting the old?
*How can I check how much data is stored? I'm thinking along the lines of array.length, but not sure if that works in Properties
*I'm assuming I need to use the parse command to retrieve it and send to the sheet at my end. That may wind up in a separate question later, but any ideas are appreciated.
function storeStats(sheetTitle) {
var docProps = PropertiesService.getDocumentProperties();
var userID = Session.getActiveUser().getEmail();
var thisData = {user:userID, sheet:sheetTitle};
var thisDataStr = JSON.stringify(thisData);
var useData = "USEDATA"; //name of the properties store maybe
docProps.setProperties(useData,thisDataStr);
Logger.log(useData.length);
//send when enough values are present
//use parse to extract and send?
// /*if(/*see how many values are in the data set*/) {
//parse values from value set array
//send the whole batch to the range on the collection sheet
//} */
}
No errors are created thus far, but this only returns one email address and one sheet name rather than all values send from previous function calls.
docProps.setProperties(useData,thisDataStr); is not adding data to "USEDATA" if you want to add or append data to it you need to do something like this:
docprops.setProperty('USEDATA', docprops.getProperty('USEDATA') + thisDataStr);
Example:
function propertiesTest() {
var ps=PropertiesService.getScriptProperties();
ps.setProperty('test','');
for(var i=0;i<10;i++) {
ps.setProperty('test',ps.getProperty('test') + '\n' + i)
}
Logger.log(ps.getProperty('test'));
}
I've a table of unknown data (some columns and rows ) ,I'm at the point where i require to use the function table.updateData() which requires column id to be existing within the data construction which i can't guarantee as the data are pulled from an unknown source .
is there's a way around this or is there's any alternative way of updating the data later ?
p.s. i only use vanilla javascript not jquery
There needs to be a unique index set on each row of the data in order for Tabulator to know which row you want to refer to.
You can set this to any column field in the row data using the index option in the table constructor
var table = new Tabulator("#example-table", {
index:"age", //set the index field to the "age" field.
});
By default this is set to the id filed
If you want to set this locally you can use a mutator to create a value in this field for you:
//define variable to count index's to ensure they are unique
var index = 0;
//define custom mutator
var idMutator = function(value, data, type, params, component){
//value - original value of the cell
//data - the data for the row
//type - the type of mutation occurring (data|edit)
//params - the mutatorParams object from the column definition
//component - when the "type" argument is "edit", this contains the cell component for the edited cell, otherwise it is the column component for the column
return index++; //return the index for the row.
}
//column definition
{field:"id", mutator:idMutator, visible:false}
However if you are updating the data from a remote source then there is no wat to tie that back to the data in your table.
It is standard practice to include an index or unique identifier in the data of this sort to allow syncing between client and server side
Hi i have add to cart button in my site. When button is clicked then the value in the form is store to a variable . var cartData = $('form').serialize();
My requirement is when the user select select next product in the page without refreshing , the form data need to save in var cartData without losing previous data,i.e i need to save this data as array. How can i do that. when i use var cartData = $('form').serializeArray(); then the cartdata only contain new valus , not previous values of form serialize.
form data need to save in var cartData without losing previous data,i.e i need to save this data as array
So you can push serialize result to actual array. For example:
var cartData = [];
// Save first form
cartData.push($('form').serialize());
// Later next form
cartData.push($('form').serialize());
This way you can store all forms you need in one data array.
I have two tables A & B, in table B I have a column of type pointer, each field points to a class in table A.
I need to know how to query table B based on the value of a particular field in the pointer column.
So for example, I have 4 objects (records) in table B, and in the pointer column I have pointer1, pointer2, pointer3 and pointer4. So if I want to carry out a query on table B and I want to extract the record with the field value of pointer3 how do I do this in javascript?
Based on your comment I would suggest storing both object IDs for each row. You could use Parse.when(recordA.save(), recordB.save()).then(...) to wait until both finished if you needed to provide feedback in the UI.
An alternative is to just store the object ID for the table B record and in the success handler you'll get back the updated record that'll include the pointer where you can then execute another save. This is slow as it will do two saves in sequence instead of kicking both off at once.
So after a long time searching and looking around and asking questions I figured it out myself in the end. I needed to pass in an object in the query.equalTo method like so:
query.find({
success: function(results) {
var detailsObject = results[0];
detailsObject.set("uuid", uuid);
detailsObject.set("proximity", prox);
detailsObject.set("campaignId", campaignId);
detailsObject.set("location", location);
detailsObject.set("sub_location", subLoc);
detailsObject.save(null, {
success: function(detailsObject) {
var content = Parse.Object.extend("Content");
var contentQuery = new Parse.Query(content);
var id = detailsObject.id;
contentQuery.equalTo("descId", detailsObject);
So "descId" is the pointer column in my content table and rather than trying to query the value in the field (object id of details object), I needed to pass the details object into the query.equalTo
I hope this is of benefit to someone else.
I have list of students like as follows form from user input form:
//student form input for 1st time
var student={name:"a",roll:"9",age:13}
//student form input for 2nd time
var student={name:"b",roll:"10",age:14}
//student form input for 3rd time
var student={name:"c",roll:"11",age:15}
Actually, i am developing phonegap applications. Each time the user submit form-input i.e. student information, I want to save them into localstorage. Finally, when online, i want to sync them. I know i can store them in localstorage as follows:
localStorage.setItem("studentinfo", JSON.Stringfy(student));
But, this will remove the first student info in the local storage when i save second student info.
Infact, when i save first, second and third input respectively, i want to add them in localstorage array and finally the result in localstorage should be like
key=studentlist,
value=[
{name:"a",roll:"9",age:13},
{name:"b",roll:"10",age:14},
{name:"c",roll:"11",age:15}
]
How can it be done in localstorage or phonegap localstorage?
You want to hold all your students in an array like this:
var students = [];
students.push({name:"a",roll:"9",age:13});
students.push({name:"b",roll:"10",age:14});
students.push({name:"c",roll:"11",age:15});
And then store that in localStorage:
localStorage.setItem('studentsInfo', JSON.stringify(students));
The best way to do that would be with a function like this:
// When you get more student information, you should:
var addNewStudent = function (name, roll, age) {
// retrieve it (Or create a blank array if there isn't any info saved yet),
var students = JSON.parse(localStorage.getItem('studentsInfo')) || [];
// add to it,
students.push({name: name, roll: roll, age: age});
// then put it back.
localStorage.setItem('studentsInfo', JSON.stringify(students));
}