2

Is there any easy way to create a a listview in HTML and set an onClick() listener for it like it can be done in Android? My requirement is that I want to retrieve data from the server and display it in a listview to the user. The data will be retrieved like - 10 rows at a time.

Then if the user clicks on more, next 10 rows will be retrieved. Then if the user clicks on a particular list item, show the details in another page.

2
  • You can use jquery datatable. Commented Dec 18, 2012 at 17:23
  • @Ashwin: Did you get solution of your this requirement? I'm looking out for the same workaround. Commented Mar 13, 2015 at 7:39

5 Answers 5

1

A list in HTML looks like this.

<ul>
   <li><a href="details/url/id">Title</li>
   <li><a href="details/url/id">Title</li>
</ul>

The urls can goto the details page.

To add a more button you would use javascript and ajax to get more rows from the server, and append more items to the list when you get the response.

Sign up to request clarification or add additional context in comments.

4 Comments

But how will I know which row has been clicked?
How to dynamically append rows, like you said?
@Ashwin Each url will have an id which will let the server know which detail to display.
@Ashwin appending rows using javascript is something that is easily googlable. You may want to get a book about javascript/html.
1

It's just a fast solution which uses Mootools, I consider your input is JSON which contain items in list array:

new Request.JSON(
{
    url: '/list.json', 
    onSuccess: function(json)
    {
        json.list.each(function(key, val)
        {
            new Element('LI')
                .set('text', val)
                .addEvent('click', function()
                {
                    alert('item '+key+' pressed');

                    // alert('item '+val.id+' pressed');
                    // considering val is an object instead of raw string, this way you must change set to something like this set('text', val.text)

                })
                .inject($('list'));
                // any other thing you want add to your list item 
        });
    }
}).get();

<ul id="list"></ul>

Key is the position of item in array, you can use an id instead which I added in a comment.

Comments

1

Rather than paginating the table, I prefer to use virtual scrolling like in SlickGrid.

SlickGrid has many modes of operation, but its core functionality is to only render the HTML of the rows you're currently looking at. As you scroll, the rows are dynamically created and destroyed as necessary. This allows you to display a grid with millions of rows.

The API allows you to load data on-demand, so rows will be fetched from the server (in groups of n) only as you scroll the grid.

Comments

0

You can try Jquery Data Tables:

http://datatables.net/

Comments

0

I suggest Ember.js. Ember.js has a powerful system of bindings and templates which are used to automagically synchronise Javascript objects with eachother and the DOM. It's overkill for what you're doing, but it's worth it if you're going to be doing anything complex with that list.

The Docs for Ember.CollectionView are here:

http://emberjs.com/api/classes/Ember.CollectionView.html

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.