Extjs 4.2: Get multiple selected cell and get values - extjs

I currently have this code for my method:
createPlaylist:function(record){
var scope = this;
var vo = record;
var sel = scope.getShowImages().getSelectionModel().getSelection();
var filename = sel[0].data.filename;
console.log(filename);
}
All I get is the value of the first cell selected, but since my seltype of my grid is checkboxmodel, I want to get all the values of the selected cells.

i assume you are using a checkcolumn. in your handler, you can try the following:
var r = grid.store.getRange();
var selected = [];
for (var i = 0; i < r.length; i++) {
if (r[i] != null) {
if (r[i].data.checkcolumn_dataIndex) { //checks if row is selected
selected.push(r[i].data);
}
}
}

Related

Better way to get values of datagrid cell

i have got dategrid which populated from sql query
HPEntities db = new HPEntities();
var queryTable4 = db.Database.SqlQuery<Lbrctn>("select * from Lbrctn");
var u = queryTable4.ToList();
DG_Example.ItemsSource = u;
i want to get the values of those row of my dataGrid which has checked. and send to Stored Procedure
so i try this code:
for (int i = 0; i < DG_Example.Items.Count - 1; i++)
{
mChkBox = DG_Example.Columns[0].GetCellContent(DG_Example.Items[i]) as CheckBox;
if (mChkBox.IsChecked == true)
{
var DaSelect = DG_Example.Columns[1].GetCellContent(DG_Example.Items[i]) as TextBlock;
var MNameTBk = DG_Example.Columns[2].GetCellContent(DG_Example.Items[i]) as TextBlock;
var ChiCodeTBk = DG_Example.Columns[3].GetCellContent(DG_Example.Items[i]) as TextBlock;
var ChiNameTBk = DG_Example.Columns[4].GetCellContent(DG_Example.Items[i]) as TextBlock;
var IntenCodeTBk = DG_Example.Columns[6].GetCellContent(DG_Example.Items[i]) as TextBlock;
var PeDescTBk = DG_Example.Columns[7].GetCellContent(DG_Example.Items[i]) as TextBlock;
db.sp_Ins_inten // using Stored Procedure
(
IntenCodeTBk.Text.Trim(),
MNameTBk.Text.Trim(),
Convert.ToInt32(chiCodeTBk.Text.Trim()),
ChiNameTBk.Text.Trim(),
PeDescTBk.Text.Trim(),
DaSelect.Text.Trim()
);
db.SaveChanges();
}
}
is there a better way than GetCellContent to get values of datagrid row I could use?
thanx in advance
all values can be found in a data item, displayed in a DataGridRow (except probably CheckBox, which is likely not bound):
for (int i = 0; i < DG_Example.Items.Count - 1; i++)
{
mChkBox = DG_Example.Columns[0].GetCellContent(DG_Example.Items[i]) as CheckBox;
if (mChkBox.IsChecked == true)
{
Lbrctn item = DG_Example.Items[i] as Lbrctn;
db.sp_Ins_inten // using Stored Procedure
(
item.IntenCodeTBk,
item.MNameTBk,
item.Convert,
item.ChiNameTBk,
item.PeDescTBk,
item.DaSelect
);
db.SaveChanges();
}
}

Re-set checkboxes to true (dealing with blanks)- Google Apps Script

I found the snippet below here: Re-set checkboxes to false - Google Apps Script
I'm interested in editing this to set false checkboxes to true, specifically adding to it to skip blank cells. Can't find anything helpful on skipping blanks.
function resetCheckBoxesAllSheets() {
var ss = SpreadsheetApp.getActive();
var allsheets = ss.getSheets();
for (var s in allsheets){
var sheet=allsheets[s]
var dataRange = sheet.getRange('A4:Z100');
var values = dataRange.getValues();
for (var i = 0; i < values.length; i++) {
for (var j = 0; j < values[i].length; j++) {
if (values[i][j] == true) {
values[i][j] = false;
}
}
}
dataRange.setValues(values);
}
}
If you wish to flip flop the values of a set of checkboxes this will do it for a given column active range:
Note: capitalization counts and yes those are strings. If you have any doubts about it then use your script editor's debugger to see what is in your checkboxes. That's how I figured it out when I started playing with them.
function resetCheckBoxesAllSheets() {
var ss = SpreadsheetApp.getActive();
var sheet=ss.getActiveSheet()
var dataRange = sheet.getActiveRange();
var values = dataRange.getValues();
for (var i=0;i<values.length;i++) {
values[i][0]=values[i][0]?"FALSE":"TRUE";
}
dataRange.setValues(values);
}
So in your particular case, assuming everything else in your function works then try this:
function resetCheckBoxesAllSheets() {
var ss = SpreadsheetApp.getActive();
var allsheets = ss.getSheets();
for (var s in allsheets){
var sheet=allsheets[s]
var dataRange = sheet.getRange('A4:Z100');
var values = dataRange.getValues();
for (var i = 0; i < values.length; i++) {
for (var j = 0; j < values[i].length; j++) {
if (values[i][j]) {
values[i][j] = "FALSE";
}
}
}
dataRange.setValues(values);
}
}

Combine multy arrays side by side google script

I have this code on Google script for get arrays from Sheet1 by criteria in Sheet2 at Sheet3. But now arrays placed only one under the other. What I need is place every new array from 'v' in next 5 columns like in example on my spreadsheet.
Secondly - before this, I used filter with search formula, that allow me use wildcards like * or ?. How I can use wildcards or regexp in my new function?
I would be grateful for any help.
function getval(){
var ss = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Sheet1");
var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Sheet2");
var sspodbor = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Sheet3");
var range = ss.getRange("A2:A29");
var values = range.getValues();
var rangez = sheet.getRange("A1:A14");
var valuesz = rangez.getValues();
var z = []
for (var x = 0; x<valuesz.length; x++){
z.push(valuesz[x])
}
var v = [];
for (var q = 0; q < valuesz.length; q++){
for (var s = 0; s < values.length; s++){
if(values[s][5] == z[q]){
v.push([values[s][0],values[s][1],values[s][2],values[s][3],values[s][4]]);
}
//I am guessing that here must be a separating function
}
}
var range = sspodbor.getRange(4, 1, v.length,v[0].length);
range.setValues(v);
}
My spreadsheet: https://docs.google.com/spreadsheets/d/1o7ErbeFHA7yyxMC0HMn3Uj5ZBRcy2uAwa1UpolVpBFI/edit?usp=sharing
Spreading the Groups out Horizontally
It's not the prettiest solution you'll ever see and hopefully others will look it over and make improvements but here it is.
function getval()
{
var Sheet1 = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Sheet1");
var Sheet2 = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Sheet2");
var output = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("output");
var knew = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('knew');
var knewrange = knew.getRange(1,1,10,100);
var pipe = '';
var range1 = Sheet1.getRange("A2:F29");
var values1 = range1.getValues();
var range2 = Sheet2.getRange("A1:A14");
var values2 = range2.getValues();
var z = [];
for (var x = 0; x<values2.length; x++)
{
z.push(values2[x])
}
var v = [];
for (var q = 0; q < values2.length; q++)
{
for (var s = 0; s < values1.length; s++)
{
if(values1[s][5] == z[q])
{
v.push([values1[s][0],values1[s][1],values1[s][2],values1[s][3],values1[s][4],q]);
}
}
}
var vlength=v.length;
var range3 = output.getRange(1, 1, v.length,6);
range3.setValues(v);
var w = [];
var voff = 0;
var hoff = 0;
for(var m=0;m<10;m++)
{
w[m]=[];
for(var n=0;n<100;n++)
{
w[m][n]='' ;
}
}
var color = ['yellow','orange'];
for(var i=0;i<v.length;i++)
{
for(var j=0;j<5;j++)
{
if(i-voff==0){knew.getRange((i-voff + 1),(j + hoff + 1),4,5).setBackground(color[v[i][5] % 2])};
if((i-voff)==0 || v[i][5] == v[i-1][5])
{
w[i - voff][j + hoff]=v[i][j];
}
else
{
voff = i;
hoff += 5;
w[i - voff][j + hoff]=v[i][j];
}
}
}
knewrange.setValues(w);
}
I copied the data from your spreadsheet and the the original getval function. I ended up changing some of the names so I could figure out where to find the data easier. It was a difficult problem for me and one that i enjoyed.
Thanks

AS3 - Auto refreshing display after updating array

So, basically I'm reinventing the wheel by trying to make a sort of spreadsheet in flash for tracking member growth in a game. In this one section I'm adding member names to an array and then placing the names into dynamically created tiles with text fields attached to display the name.
I have a save button which saves the array, and if I save, close, and reopen, then I can see the members I have added. However, I would like it to refresh the stage as soon as the array is changed to reflect the changes made (update the spreadsheet). I will also be adding and removing other tiles dynamically, but I can extrapolate the solution to this problem to all of those later.
Here's the code I have to add members and create the display:
public var mainArray:Array = new Array;
public var i1:Number = 0;
public var memberBox:MovieClip = new MovieClip();
public var MAX_ROWS = 0;
public var MAX_COLS = 0;
public function Tracker() {
MAX_COLS = mainArray.length - 1;
addBtn.addEventListener(MouseEvent.CLICK, addFun); //atchaed to button on stage
public function addFun($e:MouseEvent):void{
mainArray[i1] = [];
mainArray[i1][0] = addNameTxt.text //attached to textfield on stage
i1++;
loadMembers();
public function loadMembers():void{
var multiDimensionalArray:Array = new Array();
//initalize the arrays
for (var row = 0; row <= MAX_ROWS; row++)
{
var boolArray:Array = new Array();
for (var col = 0; col <= MAX_COLS; col++){
boolArray.push(false);
}
multiDimensionalArray.push(boolArray);
}
//now we can set the values of the array as usual
for (var row = 0; row <= MAX_ROWS; row++)
{
for (var col = 0; col <= MAX_COLS; col++){
multiDimensionalArray.push(1); ;
}
}
//create a column of tiles based on mainArray length with a textfield attached to each
buildLevel(multiDimensionalArray);
}
public function buildLevel(s:Array){
var txtArray:Array = new Array();
memberBox.name = "tileHolder";
for(var i=0; i < MAX_ROWS + 1; i++){
for(var o=0; o < MAX_COLS + 1; o++){
var currentTile:MemberBox = new MemberBox();
currentTile.x = i*150;
currentTile.y = o*25;
currentTile.name = "b"+o;
memberBox.addChild(currentTile);
//currentTile.gotoAndStop(int(s[o][i]));
var memberTxt:TextField=new TextField();
currentTile.addChild(memberTxt);
memberTxt.width = 150;
memberTxt.height = 25;
txtArray[o] = memberTxt;
txtArray[o].text = mainArray[o][0];
}
}
memberBox.x = 60;
memberBox.y = 170;
addChild(memberBox);
}
}
The ideal solution would be to attach event listeners to the Array, however, Arrays don't fire events.
Solution #1: Managed Updates
Rather than allowing any piece of code to modify your array directly, write a function that handles updating your array. This way, you can know when to update the display at the same time.
public var mainArray:Array = new Array;
public var i1:Number = 0;
public var memberBox:MovieClip = new MovieClip();
public var MAX_ROWS = 0;
public var MAX_COLS = 0;
public function Tracker() {
MAX_COLS = mainArray.length - 1;
addBtn.addEventListener(MouseEvent.CLICK, addFun); //attached to button on stage
public function addFun(e:MouseEvent):void {
mainArray[i1] = [];
mainArray[i1][0] = addNameTxt.text //attached to textfield on stage
i1++;
loadMembers();
}
public function loadMembers():void {
var multiDimensionalArray:Array = new Array();
//initalize the arrays
for (var row = 0; row <= MAX_ROWS; row++) {
var boolArray:Array = new Array();
for (var col = 0; col <= MAX_COLS; col++) {
boolArray.push(false);
}
multiDimensionalArray.push(boolArray);
}
//now we can set the values of the array as usual
for (var row = 0; row <= MAX_ROWS; row++) {
for (var col = 0; col <= MAX_COLS; col++) {
multiDimensionalArray.push(1); ;
}
}
//create a column of tiles based on mainArray length with a textfield attached to each
buildLevel(multiDimensionalArray);
}
public function buildLevel(s:Array) {
var txtArray:Array = new Array();
memberBox.name = "tileHolder";
for (var i:int = 0; i < MAX_ROWS + 1; i++) {
for(var o=0; o < MAX_COLS + 1; o++) {
var currentTile:MemberBox = new MemberBox();
currentTile.name = i + "_" + o;
currentTile.x = i*150;
currentTile.y = o*25;
memberBox.addChild(currentTile);
//currentTile.gotoAndStop(int(s[o][i]));
var memberTxt:TextField=new TextField();
currentTile.addChild(memberTxt);
memberTxt.width = 150;
memberTxt.height = 25;
txtArray[o] = memberTxt;
txtArray[o].text = mainArray[o][0];
}
}
memberBox.x = 60;
memberBox.y = 170;
addChild(memberBox);
}
public function modifyArray(row:int, col:int, value:*):void {
// Update our array.
mainArray[row][col] = value;
// Update our tile.
var tile:MemberBox = memberBox.getChildByName(row + "_" + col);
tile.getChildAt(0).text = value;
}
}
When you actually modified your array, you'd do that with your function, rather than a direct mainArray[o][i] approach.
// Instead of this
mainArray[o][i] = "foo";
// You'd do this
modifyArray(o, i, "foo");
Update: I'm not sure how better to explain this, so I've posted working example that you can view. It contains the class, and the document code, the fla, and the swf with working updates to the spreadsheet. Let me know if that resolves the issue: SpreadSheet Test # Dropbox
Solution #2: Poll for Changes
Hold two versions of your array in memory. The first is the one you're actively editing, the second is an untouched duplicate to compare against the first. Every so often (once per second?) you iterate over the entire dataset and look for differences. When one is found, update the duplicate array and the displayed spreadsheet.
Here's an example of how you'd do that:
import flash.utils.*;
var last:Number = flash.utils.getTimer();
this.addEventListener("enterFrame", checkData);
var foo:Array = ["a", "b", "c"];
var fooBackup:Array = [];
function update():void {
var txt:TextField;
for (var i:int = 0; i < foo.length; i++) {
// If we don't have a representation of this index, create one.
if (!this.getChildByName("tile"+i)) {
txt = new TextField();
txt.name = "tile" + i;
txt.text = foo[i];
this[txt.name] = txt;
addChild(txt);
txt.y = i * 20;
}
// Update the data if inconsistent.
txt = this.getChildByName("tile"+i) as TextField;
if (fooBackup.hasOwnProperty(i) == false || foo[i] != fooBackup[i]) {
fooBackup[i] = foo[i]
txt.text = foo[i];
trace("Index " + i + " changed. Updated backup, and display.");
}
}
}
function checkData(e:Event):void {
var now:Number = flash.utils.getTimer();
// If the last time we checked is greater than a second, run the check again.
if (now - last > 1000) {
// Update last checked index;
last += 1000;
// For the sake of argument, let's randomly change an index to a random value.
foo[random(0, foo.length-1)] = random(-1000, 1000);
update();
}
}
function random(low:Number=0, high:Number=1):Number {
/* Returns a random number between the low and high values given. */
return Math.floor(Math.random() * (1+high-low)) + low;
}
Solution #3: Roll your own Array
As outlined by Adobe's Extending the Array class, you can subclass Arrays and from there add your own event dispatches when you add/remove entries. This is the more adventurous solution, and (in my humble opinion) the best as it maintains code consistency, while giving broad and efficient powers.

flex array filter duplicates

i'm urgently looking for a solution to delete all duplicates from an array in Flex.
I need to filter out all duplicates in the filteredData array.
The indexOf doesn't do the trick here, i believe because objects are being loaded into the array.
Thanks in advance
var columnArray:Array = ['ingenre']; //Datagrid column names to filter on
var songArray:Array = ['id']; //Datagrid column names to filter on
var gridDataProvider:ArrayCollection = PhotoData; //Name of datagrid's dataprovider. In this case e.g. databases
var dataGridName:String = 'dgUserRequest'; //Name of the datagrid you are filtering by
 
//Do not edit code past this point
var filteredData:Array = [];
var added:Boolean=false;
var i:int;
var j:int;
var filtertxt: String;
var matchtxt:String;
 
// Loop Through Grid
for(i=0; i < gridDataProvider.length; i++){
added = false;
 
//Loop through grid column
for(j=0; j<columnArray.length; j++){
if(gridDataProvider[i][columnArray[j]]!=null){
//Grab datagrid cell contents, trim it, and convert to lowercase for comparison.
var filterString:String = gridDataProvider[i][columnArray[j]].toString().toLowerCase();
var songIdString:String = gridDataProvider[i][songArray[j]].toString().toLowerCase();
//Compare the datagrid string(filterString) to the user typed string(filterText).
if(!added){
// loop through the Array & check if there is a match.
for (var k:int = 0;k < filterText.length; k++)
{
filtertxt = filterString.toLowerCase();
matchtxt = filterText[k].toLowerCase();
//if(filterString.toLowerCase() == filterText[k].toLowerCase()){
if(filtertxt.search(matchtxt) >= 0){
if (cmd_classic.selected == true)
{
trace(filteredData.indexOf(songIdString));
if(filteredData.indexOf(songIdString) < 0)
{
if ((filtertxt.search("class") == -1) && (filtertxt.search("baroque") == -1))
{
if (filteredData.indexOf(songIdString) == -1)
{
filteredData.push(gridDataProvider[i]);
added = true;
}
}
else
{
break;
}
}
}
else
{
if (filteredData.lastIndexOf(songIdString) <= 0)
{
filteredData.push(gridDataProvider[i]);
added = true;
}
}
}
}
}else{
//Do nothing, break out.
break;
}
}
}
}
Flex doesn't really have a Set class that I'm aware of. But what I've done in the past when I need to get a list of unique values from a list is to create a new Dictionary. Loop through the list using the values I want to dedupe as the key and getting the key set when I'm finished.

Resources