Verify input on change in dynamic list Vue - javascript

Based on a drop down that has a value in the 1-10 range I am displaying N Rows (N = value of dropdown)
Each row acts as an object because it has 3 properties: x,y,z. All the rows I generate are stored in an array so the final format of the data is:
data:{
rows: [
{x:0,y:0,z:value},
.......
]
}
I have to verify that for each row the value of x,y,z doesn't pass 100 and if it does display an error.
I've tried doing it with a function that parses the array on each input change but besides the fact that it seem very inefficient it sometimes doesn't work.
How can I handle this validation on dynamically generated inputs ?
Thank you in advance!

Make a watcher that observes the array changes :
data:{
rows: [
{x:0,y:0,z:value},
.......
]
},
watch:{
rows:{
handler(val){
let check=this.rows.every(row=>Object.values(row).every(v=>v<100))
if(!check){
//error
}
},
deep:true
}
}

Related

Writing array to single row

I have created an API which iterates through JSON format data, reading 2 items per ID. I'm storing this data in an array called values[].
How about this modification?
Modification points:
In order to put the values of values to one row, please modify values.push([timestamp, price]); to values.push(timestamp, price);. By this, each value is put in values which is one dimensional array.
In order to put values from the row 3, in this modification, it checks whether the row 3 for putting values is empty.
When above points are reflected to your script, it becomes as follows.
Modified script:
From:
values.push([timestamp, price]);
}
var ss = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("rawStockData");
ss.getRange("A3:BH3").setValues(values);
}
To:
values.push(timestamp, price); // Modified
}
var ss = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("rawStockData");
var range = ss.getRange(3, 1, 1, values.length); // Modified
if (range.isBlank()) { // Added
range.setValues([values]);
} else {
ss.appendRow(values);
}
}
References:
push()
appendRow(rowContents)

Add element to multi row array with angular / javascript

I have the following array with data:
[
{"count":1,"title":"Ark: Survival","platform":"Playstation PS4"},
{"count":2,"title":"Lara Croft:", "platform":"Playstation PS4"},
{"count":1,"title":"Madden NFL", "platform":"Playstation PS4"}
]
All in my angular Cart scope:
var data = $scope.cart;
now i would like to add to each row the order number, so i use a push:
$scope.cart.push({"orderNumber": $scope.OrderNumber});
the problem is that is adds the order number but as a separate row and not inside each of the rows. so my desired output should look like this:
[
{"count":1,"title":"Ark: Survival","platform":"Playstation PS4","orderNumber":1 },
{"count":2,"title":"Lara Croft:", "platform":"Playstation PS4","orderNumber":1},
{"count":1,"title":"Madden NFL", "platform":"Playstation PS4","orderNumber":1}
]
how would i push to each row of the array? i tried several versions but can't seem to get it to work.
in order to achieve that you should iterate through each object and set order number separately
angular.forEach($scope.cart, function (value, key) {
value.orderNumber = $scope.OrderNumber;
});
You need to iterate over each item and add the orderNumber as a property for each item. So you can use forEach function of the angular for that.
angular.forEach($scope.cart, (item) => item.orderNumber = $scope.OrderNumber)
just got an answer that i implemented but the user has deleted the response, however it works perfect, this was the solution that i used:
$scope.cart.forEach(item => item.orderNumber = $scope.OrderNumber)

How to implement bi-directional connection between two arrays?

In my app I have an ItemsService which gets Items from Server and stores them as JSON objects in its cache variable. Items can be present in many places, e.g. in table or in graph/chart and so on.
For example, when I initialize a table - I need to pick only specific Items from cache, e.g. 1st, 3rd, 7th.
How to implement bi-directional connection between them? Basically I want table to contain references to specific items from cache so when I change an Item either in cache or in table - its state will be in sync all the time because it's the same Item.
Also when I delete Item from table - it needs to be removed from cache.
Here's example of table and cache structures:
Table:
table: {
"36": { // it's a name of a row
"72": [items], // it's a name of a column with corresponding items
"73": [items],
"74": [items]
},
"37": {
"72": [],
"73": [items],
"74": [items]
},
"38": {
"72": [],
"73": [],
"74": []
}
}
ItemsService cache (simplified version):
ItemsService = {
cache: [items]
};
Item structure:
{
id: 3,
parent_id: 1,
name: 'First Item',
siblings: [1,2,3],
active_users: [{user_id: 1, avatar_url: 'http://...'}, ...],
// 50 more fields :)
}
Also need to point out that I use angular-ui-sortable plugin to allow dragging of Items between columns/rows and I need to provide ng-model with array(I think). Here's how it looks right now:
<td ui-sortable="vm.sortableOptions"
ng-model="vm.table[row.id][column.id]">
<sb-item itemid={{item.id}}
ng-repeat="item in vm.table[row.id][column.id]">
</sb-item>
</td>
Unless for some reason you have to use two separate arrays, have you considered using a filter?
Your best bet would be objects. Variables that hold objects in javascript aren't really holding the object but a reference to said object. When you pass that variable into another one, the reference value gets copied so both variables point toward the same object.
var a = { 0: 'Property 0' };
var b = a;
b[0] = 'Property 0!'; //a[0] also the same.
delete b[0]; //a[0] nor b[0] exist anymore.
Using objects (rather than JSON) would work.
Then your cache and your table both point to same item objects. If you change something in the object, it is reflected at both ends.
var cacheArray = [{ item: 1 }, { item: 2}];
table[0][0] = cacheArray[0];
console.log(table[0][0].item); // 1
cacheArray[0].item = 9;
console.log(table[0][0].item); // 9.
Please note that the array and the table have not changed. They still point to the same objects.

dgrid not showing all rows in the store

I have a data array with 165 elements, and I am showing them in an OnDemandGrid, sorted by a date field. However, when the grid shows up, only the last 140 elements in the data array are shown (i.e., the elements with the 140 most recent dates). Still, if I click the date header to reverse the sort, the first 140 elements show (i.e., the elements with the 140 oldest dates). So my guess is that somehow the mechanism of lazy loading is not working, still I don't get why only the last portion of the array is shown instead of the first. I am not using pagination, nor I set other options related to the size. Any suggestion?
The grid is added to a div which is already in the page:
<div id="navList" class="dgrid-autoheight"></div>
Here's the code for the grid, below you can find the data array:
function fillNavList(data) {
var columns =
[
{
field : "date",
label : L["date"]
},
{
field : "value",
label : L["value"]
},
{
field : "dateModification",
label : L["dateModification"]
},
{
field : "status",
label : L["status"]
},
{
field : "valueRefId",
label : L["valueRefId"]
}
];
require(
[
"dojo/on",
"dstore/Memory",
"dstore/Filter",
"dgrid/OnDemandGrid",
"dojo/_base/declare"
], function(on, Memory, Filter, OnDemandGrid, declare) {
var store = new Memory({
data : data
});
var navList = new (declare(
[
OnDemandGrid
]))({
columns : columns,
sort: "date",
collection : store,
addUiClasses : false
}, "navList");
});
}
And here's the data:
[{"date":"2000-01-31","value":96.02,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2002-02-28","value":100,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2002-03-29","value":92.48,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2002-04-30","value":93.91,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2002-05-31","value":100.25,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2002-06-28","value":107.65,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2002-07-31","value":114.06,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2002-08-30","value":120.26,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2002-09-30","value":126.43,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2002-10-31","value":116.66,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2002-11-29","value":110.73,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2002-12-31","value":119.37,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2003-01-31","value":135.13,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2003-02-28","value":144.88,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2003-03-31","value":126.29,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2003-04-30","value":128.12,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2003-05-30","value":137.91,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2003-06-30","value":127.41,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2003-07-31","value":119.34,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2003-08-29","value":119.42,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2003-09-30","value":127.37,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2003-10-31","value":146.88,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2003-11-28","value":146.48,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2003-12-31","value":154.32,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2004-01-30","value":160.79,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2004-02-27","value":174.37,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2004-03-31","value":178.51,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2004-04-30","value":157.99,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2004-05-31","value":146.95,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2004-06-30","value":145.87,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2004-07-30","value":145.27,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2004-08-31","value":136.25,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2004-09-30","value":146.82,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2004-10-29","value":147.94,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2004-11-30","value":162.19,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2004-12-31","value":154.17,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2005-01-31","value":147.57,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2005-02-28","value":148.36,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2005-03-31","value":151.77,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2005-04-29","value":137.69,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2005-05-31","value":132.07,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2005-06-30","value":139.09,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2005-07-27","value":148.3,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2005-08-31","value":152.43,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2005-09-30","value":173.12,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2005-10-31","value":163.36,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2005-11-30","value":188.31,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2005-12-30","value":204.03,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2006-01-31","value":226.65,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2006-02-28","value":220.54,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2006-03-31","value":249.33,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2006-04-28","value":277.9,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2006-05-31","value":266.03,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2006-06-30","value":249.8,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2006-07-31","value":236.82,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2006-08-31","value":241.44,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2006-09-29","value":243.85,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2006-10-06","value":243,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2006-10-31","value":243.54,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2006-11-30","value":244.9,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2006-12-29","value":248.81,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2007-01-31","value":250.2,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2007-02-28","value":237.24,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2007-03-30","value":216.31,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2007-04-30","value":221.92,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2007-05-31","value":232.35,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2007-06-29","value":243.63,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2007-07-31","value":202.47,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2007-08-31","value":163.19,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2007-09-28","value":169.58,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2007-10-31","value":192.84,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2007-11-30","value":176.27,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2007-12-31","value":191.2,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2008-01-31","value":232.59,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2008-02-29","value":299.72,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2008-03-31","value":275.87,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2008-04-30","value":252.21,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2008-05-30","value":265.71,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2008-06-30","value":288.32,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2008-07-31","value":234.16,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2008-08-29","value":218.41,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2008-09-30","value":243.7,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2008-10-31","value":354.57,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2008-11-28","value":379.28,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2008-12-31","value":399.38,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2009-01-30","value":405.77,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2009-02-27","value":405.65,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2009-03-31","value":392.02,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2009-04-30","value":370.42,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2009-05-29","value":365.6,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2009-06-30","value":340.71,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2009-07-31","value":338.9,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2009-08-31","value":375.67,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2009-09-30","value":380.63,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2009-10-30","value":350.71,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2009-11-30","value":388.24,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2009-12-31","value":375.85,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2010-01-29","value":361.39,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2010-02-26","value":335.54,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2010-03-10","value":318.26,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2010-03-31","value":318.16,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2010-04-30","value":324.68,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2010-05-28","value":296.24,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2010-05-31","value":296.21,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2010-06-30","value":297.78,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2010-07-30","value":261.96,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2010-08-31","value":300.18,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2010-09-30","value":349.59,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2010-10-29","value":427.49,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2010-11-30","value":404.6,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2010-12-31","value":506.97,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2011-01-31","value":517.49,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2011-02-28","value":567.69,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2011-03-31","value":541.83,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2011-04-29","value":574.72,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2011-05-31","value":506.78,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2011-06-30","value":469.21,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2011-07-29","value":521.53,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2011-08-31","value":529.83,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2011-09-30","value":507.55,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2011-10-31","value":435.8,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2011-11-30","value":488.27,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2011-12-30","value":480.31,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2012-01-31","value":462.31,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2012-02-29","value":465.92,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2012-03-30","value":490.21,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2012-04-30","value":484.9,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2012-05-31","value":480.55,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2012-06-29","value":393.47,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2012-07-31","value":438.26,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2012-08-31","value":410.83,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2012-09-28","value":375.59,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2012-10-31","value":319.01,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2012-11-30","value":315.91,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2012-12-31","value":318.33,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2013-01-31","value":351.63,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2013-02-28","value":377.62,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2013-03-29","value":412.7,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2013-04-30","value":452.87,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2013-05-31","value":453.45,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2013-06-28","value":439.18,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2013-07-31","value":421.47,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2013-08-30","value":375.51,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2013-09-30","value":385.31,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2013-10-31","value":413.41,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2013-11-29","value":461.28,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2013-12-31","value":455.58,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2014-01-31","value":448.93,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2014-02-28","value":455.05,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2014-03-31","value":476.19,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2014-04-30","value":488.89,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2014-05-30","value":467.05,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2014-06-30","value":478.1,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2014-07-31","value":488.85,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2014-08-29","value":534.46,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2014-09-30","value":629.01,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2014-10-31","value":618.48,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2014-11-28","value":699.19,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2014-12-31","value":762.46,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2015-01-30","value":815.27,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2015-02-27","value":811.23,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2015-03-31","value":842.4,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2015-04-30","value":775.2,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2015-05-29","value":807.2,"dateModification":"2015-07-31","status":"Final","valueRefId":0},{"date":"2015-06-30","value":758.21,"dateModification":"2015-07-31","status":"Final","valueRefId":0}]
Thanks in advance
Found it! Turns out my data elements did not have an id attribute, and this is somehow messing up the grid's ability to render the rows. I found a pointer to the solution in https://github.com/SitePen/dstore/blob/master/docs/Stores.md where it says:
The data should be an array of objects, and all the objects are considered to be existing objects and must have identities
After adding a unique identifier to my data, everything works ok.

How to get the object which represents the selected row in a slickgrid

I have a webpage with a slickgrid which renders an array of objects on a grid. I want to do some dynamic stuff (a master-detail like setup) when the selected row changes. However to be able to do this, I would need the data of the selected row. I know that the grid.getCurrentCellNode() function will give me the dom element of the current node, but what I am looking for is a javascript object. For instance, if I use an array of objects like the one below
data = [
{id:1, name:'Khaja', dob:'26/07/1985'},
{id:2, name:'Iqbal', dob:'26/07/1935'}
......
...
];
and if my selected row is the row with id equal to 2, I want to be able to retrive the object {id:2, name:'Iqbal', dob:'26/07/1935'} Is there a way through which I can get this object?
You can use the onSelectedRowsChanged event and the getSelectedRows method.
data[i]={
ID: json[i].ID,
Name: json[i].Name,
Description: json[i].Description,
CreatedDate: myDate,
makesub: "---",
shared: json[i].IsShared
};
.....
grid.onClick = function (e, row, cell) {
if (columns[cell].id == "colname"){
// where colname is the column on which you want to trigger the click
alert("clicked:"+row+", albumID:"+data[row].ID);

Categories

Resources