In many cases you want grid to perform 3 basic operations, which are: editing, deleting and adding entries to a table. While this functionality is really easy to achieve by using MVC and entity editor, you may need to know how to perform those actions yourself.

In this demonstration you can see one of the variants how to implement this functionality. This demonstration is limited to only a single page, you might find multi-page implementation a more effective.

You have probably noticed by now, that Agile Toolkit is being smart about tracking changes on forms and if you did change anything then attempt to edit other record, you will be warned about loosing your changes.

Another quality of ATK is that form is going to auto-focus it's first field when loaded.

Add or edit record

Name Surname Gender Edit Delete
aa aa F
aaaa abbbb F
Nikhil Sharma M
luizin luizinzin M
bla blablabla M
// You might need to use $p=$this; if you are inserting this code into page/*.php

// In this example we are attempting to combine a form and a grid element on the
// single page.

$h=$p->add('View_HtmlElement')->setElement('h2')->set('Add or edit record');

// Form and grid will need to communicate to each-other so we better add them
// both to the page.

// Set source for both grid and form. Both objects are relying no dynamic query
// object, so you might apply additional conditions if you wish to.

// Again - adding fields can be done by models, but we do it manually for our
// example. Please try to use Models in your application for higher efficiency.

// This function performs two actions. First it looks into $_GET['id'] and if
// that is set, it is going to load form data from the database with specified
// id. Secondly, that ID will also be marked as Sticky, which means if you
// are to submit a form, the argument is not going to be lost.

// Below we rely on reloading parts of the page through javascript. Note that
// we either are willing to pass ID or are willing to drop it (in case cancel is clicked)


// Column with type button is going to execute ajax request to the same page
// where grid is and will pass ID through the GET argument same as button's name.
// In our case edit=213 will be added.

// if you add column 'delete' then Grid will be capable of deleting entries from the
// database. Note that all the conditions you might have applied on the grid are
// also going to be used for deleting (by cloning dynamic query object) - this is 
// to insure that user is not going to delete some non-relevant data.


blog comments powered by Disqus