Page 1 of 1

Grid with labels, loop to get the values

Posted: Mon Oct 27, 2014 8:09 am
by Takis

Hi team

I have a grid which contains only labels.
I get the values of the labels from a DB service, which work fine.
One of the labels in the grid contains an address.
But as many records returned from DB, I get of course many address labels.
The label in the grid that holds the address is called ResultText5.

I want, after the records are returned from DB and displayed in the page, to loop inside the grid, get the values of only the labels with name ResultText5, separate them with "," and save them in a local variable.

How in general can we loop on the objects inside a grid and get values?

Thanks!


Grid with labels, loop to get the values

Posted: Mon Oct 27, 2014 11:05 am
by Takis

Help!


Grid with labels, loop to get the values

Posted: Mon Oct 27, 2014 11:18 am
by Maryna Brodina

Hello!

Try the following way:

pre// get all values
var values = $('[name="ResultText5"]').map(function(index,element){
return $(element).text();
}).get().join(',');
// save the values
localStorage.setItem('values', values);/pre


Grid with labels, loop to get the values

Posted: Mon Oct 27, 2014 12:11 pm
by Takis

I love you!
Works thanks.

A general suggestion, if I may.
It would be good to be in documented examples how to do this with dynamically build grids that contains labels, buttons, checkboxes, etc, as I see many people use this approach.
I mean how to get or set properties of objects in such cases.
If documentation already exists, please give a link.

Thanks again!


Grid with labels, loop to get the values

Posted: Mon Oct 27, 2014 2:28 pm
by Maryna Brodina

:) Added your request to the doc requests update list. Hope we can add such examples.


Grid with labels, loop to get the values

Posted: Sun Nov 02, 2014 2:32 pm
by Takis

Hi

Suppose that I have a grid with 6 labels "Lable1"..."Lable6" , with text populated by DB service

Can I loop from all labels in a record and store its values in a multi dimension array? Like an expansion of the above code you gave me.

For exampe:
record1= array[1]
record2=array[2]


Grid with labels, loop to get the values

Posted: Tue Nov 04, 2014 2:17 am
by Yurii Orishchuk

Hi Panagiotis,

Yes you can do it.

this is code example:

pre

var resultArray = [];

//Where "itemName" is your item component name.
var items = jQuery('[name="itemName"]');

var labels = {
attr1: "label1",
attr2: "label2",
attr3: "label3",
attr4: "label4",
attr5: "label5"
};

for(var i = 0; i < items&#46;length; i++){
var item = jQuery(items);

Code: Select all

 resultArray[i] = []; 

 for(var j = 0; j < labels&#46;length; j++){ 
    resultArray[i][j] = item&#46;find('[name="' + labels[i] + '"]')&#46;text(); 
 }; 

};

console&#46;log(resultArray);

/pre

Regards.


Grid with labels, loop to get the values

Posted: Sat Nov 22, 2014 8:08 pm
by Takis

In one page, I am trying to get all the checkboxes that I created dynamically, that are checked and get its values.

I got up to this point of code

code
var items = jQuery('[name="mobilecheckbox_157"]');
alert ( "how many chbx:" + jQuery('[name="mobilecheckbox_157"]')&#46;length );
for (var i = 0; i < items&#46;length; i++){
var item = jQuery(items);
alert ( item&#46;text()&#46;trim() );

}
/code

I want to get only the checked and store its name in an array.


Grid with labels, loop to get the values

Posted: Sun Nov 23, 2014 11:43 pm
by Yurii Orishchuk

Hi Panagiotis:

You need to add ":checked" selector to your jQuery search.

Details: http://api.jquery.com/checked-selector/

pre

var items = jQuery('[name="mobilecheckbox_336"] input:checked');

alert("how many chbx:" + items&#46;length);
for (var i = 0; i < items&#46;length; i++) {
var item = jQuery(items)&#46;closest('[name="mobilecheckbox_336"]');

Code: Select all

 alert(item&#46;text()&#46;trim()); 

}

/pre

Regards.