开发者

Editable table in PHP

In a PHP application I'm building, I'd like to have an 'editable' table. The idea is that each row will have an edit button, which, when clicked, will replace certain fields with text fields and select lists and change to a save button. When the user clicks save, the data data should be validated and changed if appropriate.

I'm mainly tackling this as a learning project (I'm aware there's a ton of stuff already out there) and to see if I can get anything 'cool' working. I've created a PHP table-generating class that can take an array of objects as a datasource, and can have columns created based on those class methods.

e.g.

$table = new Table($dataSource);
$table->addColumn('开发者_如何学PythonName', 'getName');
$table->addColumn('Amount Due', array('getOrdersManager', 'getTotalAmountDue')); //First calls getOrdersManager() on each data item and then calls the getTotalAmountDue() on the result

I'd like to try my hand at extending this to be able to the table row and have those changes reflect on the corresponding object in the data source.

I don't really have very much experience with AJAX although it's clearly going to play a very important role in getting this to work correctly.

Any tips on how I should approach such a task?

Edit: I'm not really interesting in looking at Ajax libraries at this point (I do have some experience with jQuery). I'm more interested in learning the basics of Ajax at this point.


my tip is to use jquery(does most of the heavy lifting for you and is easy to learn).

The idea is that each row will have an edit button, which, when clicked, will replace certain fields with text fields and select lists and change to a save button

http://api.jquery.com/click/

When the user clicks save, the data data should be validated and changed if appropriate.

http://api.jquery.com/jQuery.post/


Some things to be aware of/think about:

  • Are you going to send every field change to the server, or only the whole row (the latter is more resource efficient, but not necessarily as accurate)
  • How are you going to ensure the data displayed stays accurate even if the update to the server fails for some reason (either a network failure or a DB/validation error)
  • How will you ensure the user has permission to update the record and that you don't open a security hole by allowing the AJAX responder just to update whatever record it is told to. My approach has been that if a record is shown in the interactive table then the user has the permission to update it, so a cache of record IDs is held in the session when the table is created
  • Are you going to load options dynamically? If you don't, then a long table can end up containing a lot of HTML because of repetition of the select controls, but again it is more resource efficient not to have a request every time a user clicks into a dropdown. One compromise might be to put the options into a hidden HTML field and load them dynamically into the correct place when a user clicks a dropdown
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜