Concatenating Database Output into a List Item

This forum contains topics that were moved from Get Satisfaction
Bhupinder Chawla
Posts: 0
Joined: Thu Aug 28, 2014 1:21 am

Concatenating Database Output into a List Item

Post by Bhupinder Chawla »

I have two fields in a database table (or collection, if you will) - FirstName and LastName.

I have a list object and the output from the database has to go into the List Object as follows and sorted too:

Hill, Tom
Thomas, Jill
Zycer, Adam

What JavaScript code I have to write to get into the Text field of the ListObjectItem ?

How do you really reference a database object in Data Response?

FYI - I am connecting (mapping) the FirstName and LastName to the Text field of the ListObjectItem as well as the $[] to ListObjectItem.

Thanks for your reply.

Yurii Orishchuk
Posts: 0
Joined: Fri Feb 14, 2014 8:20 am

Concatenating Database Output into a List Item

Post by Yurii Orishchuk »

Hi Bhupinder,

Here is solution for you:

1 Open list mapping.

2 Delete all response links.

3 Make link from $[] to listItem component. http://prntscr.com/4h6rgm/direct

4 Click "Add JS/Edit JS" on listItem component.

5 Populate it with following code: http://prntscr.com/4h6sxd/direct

pre

var name = value.FirstName + ", " + value.LastName;
element.find("h3").text(name);

return value;

/pre

Regards.

Bhupinder Chawla
Posts: 0
Joined: Thu Aug 28, 2014 1:21 am

Concatenating Database Output into a List Item

Post by Bhupinder Chawla »

Hi Yurli,

Good Morning!

Thanks for a quick response. It works!

I have a question - what does "h3" stand for? If I have to use it for another list in the same Page, would it change?

Thanks!

Best Regards
Bhupinder Chawla

Yurii Orishchuk
Posts: 0
Joined: Fri Feb 14, 2014 8:20 am

Concatenating Database Output into a List Item

Post by Yurii Orishchuk »

Hi Bhupinder,

"h3" is tag inside list item.

If you will use simple list item you can use code above.

But if inside your list-item you will have some other components you need to change this line of code with:

pre

//Note: you need replace "labeComponentName" with your component name.
element.find('[name="labeComponentName"]').text(name);

/pre

Regards.

Bhupinder Chawla
Posts: 0
Joined: Thu Aug 28, 2014 1:21 am

Concatenating Database Output into a List Item

Post by Bhupinder Chawla »

Hi Yurli,

Thanks for the reply, I will try this.

Also, with this concatenated field, can I get the results sorted by this concatenated field?

If yes, how can I do this?

Thanks!

Best Regards
Bhupinder Chawla

Yurii Orishchuk
Posts: 0
Joined: Fri Feb 14, 2014 8:20 am

Concatenating Database Output into a List Item

Post by Yurii Orishchuk »

Bhupinder,

In this case best way to sort it before being list builded.

For this goal you need to create generic service where you get response from other service and alter it with your need.(for example with method "sort").
See details: http://devcenter.appery.io/documentat...

Also you can do it with generic security context.
See details: http://devcenter.appery.io/documentat...

Regards.

Bhupinder Chawla
Posts: 0
Joined: Thu Aug 28, 2014 1:21 am

Concatenating Database Output into a List Item

Post by Bhupinder Chawla »

Yuri,

You have been a great help. I have another question.

I have created a grid with 3 columns. I have populated the columns from a database query by using list item in each column (do not know if this is the best approach to populate a grid from a collection or database query)

I click on one list item. I need to know the values of the corresponding list items in the same row of the grid. How do I get to know that?

Thanks!

Best Regards
Bhupinder Chawla

Yurii Orishchuk
Posts: 0
Joined: Fri Feb 14, 2014 8:20 am

Concatenating Database Output into a List Item

Post by Yurii Orishchuk »

HI Bhupinder,

You goals currently not clear, if further suggestion not help please make some screen shots and describe them.

If you want to get "text" of the clicked row, you can use following js code:

pre

var rowText = jQuery(this).closest("tr").text();
alert(rowText);

/pre

If you need make further processing with click item - you need to store inside this item "_id" and than get it. You can read more about it here http://devcenter.appery.io/tutorials/...

Regards.

Bhupinder Chawla
Posts: 0
Joined: Thu Aug 28, 2014 1:21 am

Concatenating Database Output into a List Item

Post by Bhupinder Chawla »

Yuri,

Thanks for the reply. I will send you a reply on that. Continuing on the same, I have another query:

I need to get Sum and Count of different columns in a collection and bind them to a items on the UI.

What is the graphical way to do it without getting into curl etc (which I am not able to understand).

Thanks!

Best Regards
Bhupinder Chawla

Yurii Orishchuk
Posts: 0
Joined: Fri Feb 14, 2014 8:20 am

Concatenating Database Output into a List Item

Post by Yurii Orishchuk »

Hi Bhupinder,

Here is brief plan for this:

1 create list/query service you need.
2 add datasource to the goal page.
3 invoke this datasource on event you need.
4 add JS event handler on "success" event for this datasource.
5 populate it with following code:

pre

var summ = 0;
for(var i = 0; i < data&#46;length; i++)
&#47;&#47;Note: you need replace "numberField" with your field with number
summ += parseInt(data&#46;numberField);

Appery("labelName")&#46;text("summ = " + summ);

/pre

Regards.

Post Reply