English 中文(简体)
Best Way to Ajax-Control Table Rows
原标题:
  • 时间:2009-12-15 01:13:47
  •  标签:
  • ajax
  • row

I want to be able to print out a table with x rows and about 10 columns. However, I want to be able to select rows in the table as if it was a multiple select box. Selecting the row of the table will cause an additional text area to display additional information about that row of data.

What s the best way of doing this in AJAX?

最佳回答

There are a bunch of things you need to go, but I ll give you an idea of what you need. For each row, you ll want to attach a click listener to it or you allow the click event to bubble up to the table and catch it there and then inspect which row it was in (here s how the YUI folks do this). On each HTML element, you ll want to have some way of identifying which row was clicked. It can be part of the HTML id or you can use a different attribute altogether that you retrieve with trElement.getAttribute( yourAttribute ).

Once you have the id, then you can show a textarea or make an AJAX call that grabs additional data and then displays a textarea. You ll want to define some webservice that takes an id and returns either the HTML to display or JSON data that you can parse and then build the display yourself. Depends on how much data you re sending whether it s better to return JSON or HTML, though I tend to prefer JSON. If you can select more than one row, you ll want to store which rows have been clicked somewhere in JavaScript. This is as simple as having a variable which is the set of clicked ids and everytime you click on that row you add it or remove it based on whether it was already there. You can also add a class to each selected row so the background color changes or something when it s selected.

At a high level, that s all there is to it, but I can elaborate on a specific part if you ve got more specific questions.

问题回答

暂无回答




相关问题
ajax login using httpRequest?

I am trying to develop my login script to give feedback to the user if the login is valid or not. Basically if it isn t correct a div box will show saying its wrong, if its correct it will show its ...

Virtual Tour using sketch up, ajax, flash technologies

I want to know if there are existing technology that make your 3d models in sketch into virtual tours, using either Ajax or Flash for web presentation. If there s none, which will be a good approach ...

How can i update div continuously

I have asp.net application where i have a div which showing the value from other site. The value of that site is changing continuously. I want that my div will automatically update in some interval ...

热门标签