24
Nov

PHP CRUD template for jqGrid

   Posted by: admin   in MySQL, PHP, Software Development

I have been using the JQuery for quite a while. JQuery does not have an official plugin for grids, there are several of them out there. I tried out a few and settled on jqGrid   I am very pleased with it in every way. I’ve used it in several projects and it’s always been very flexible and extendable for my needs. I’ve been able to easily add after effects like color sorting, drag and drop reorder etc. with ease. Writing the PHP for the typical CRUD (Create Read Update Delete) functions is very easy but is so boring that I had to do SOMETHING that would both give me a bit of fun and give me smoething to make this part of the process faster for me in the future. So I have a .php template here with it, I can change a few variables around and apply it to any MySQL operation that interacts with jqGrid.

define

$crudColumns =  array(
    ‘id’=>‘id’
    ,‘title’=>‘title’
    ,‘icon’=>‘icon’
    ,‘description’=>‘description’
    ,‘parent’=>‘parent_list_id’
);
$crudTableName = ‘list’;
$postConfig[‘id’] = ‘id’;

and it’ll create the select, search, paging, insert, update, delete interactions for jqGrid for you.
it also has some convenient spots to edit the sql for additional column / query manipulation. At a minimum it should serve as a good starting point for working with jqGrid beyond the examples they provide (Which are very good and helpful already). If you have any updates or suggestions for this please let me know.
-enjoy

Share and Enjoy:
  • Digg
  • Technorati
  • Google Bookmarks
  • del.icio.us
  • Facebook
  • StumbleUpon
This entry was posted on Monday, November 24th, 2008 at 12:50 pm and is filed under MySQL, PHP, Software Development. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

9 comments so far

 1 

Thank you, thank you, thank you! :)

April 16th, 2009 at 9:24 am
dochwo
 2 

thank’s a lot

May 15th, 2009 at 6:59 am
docwho
 3 

Thanks!

May 18th, 2009 at 10:26 am
 4 

Thank you for the release of this template for jqGrid. It has helped immensely thus far in my project.

I am just having a problem using a Date format in the Column. I am trying to have the field be auto-updated on the Insert or Update to the current time so that we can track actions.

I have a field in the DB table set up and am able to insert / update all of the fields but not it.

Do you think it could be because the field is not being escaped properly? I am currently installing FirePHP to see what it reports for the query.

Any ideas? Thanks in advance for your help.

Brandon R.

May 20th, 2009 at 3:44 pm
Charlie
 5 

PHP CRUD is excellent! It helped me get a project up and running quickly. Having trouble figuring how to where to modify to work with jQGrid multiple search fields. They don’t use same post parameters as the standard search. ” searchField, searchOper and searchString” aren’t used in the POST, so WHERE falls aprt in SQL query. Be grateful for any assistance. Instance of use see “Multiple Toolbar Search” New in 3.3 and most recent version 3.5 Beta has really nice integrated top search bar

May 28th, 2009 at 2:25 pm
admin
 6 

There are a lot of sql generation libraries that would make this easier for you, but if you want to generate a multiple search statement yourself you can parse the arrays of search columns and values into a long WHERE clause for SQL, make sure to only do it for columns that have a value defined. There Where caluse will look something like: WHERE column like ‘%searchterm%’ AND ‘column2′ like ‘searchterm’ this could produce some very slow queries, depending on the amount of data being searched.

May 29th, 2009 at 8:28 am
admin
 7 

Dates are always tricky. You probably have the wrong format or need to use a date function in your query for that column to format it properly. What I don in my apps is have a case statement that runs through all of the vars submitted to the page and it normalizes each column to make sure it’s a valid value and in the proper format for the query.

May 29th, 2009 at 8:32 am
 8 

coool… many thanks, create some modification for inserting with a selecting columns got from another tables but you help a lot for starting build the system

May 31st, 2009 at 7:23 am
Kandido
 9 

Thanks a lot buddy!!!!
nice code, easy to understand. ñ_ñ¡

June 30th, 2009 at 1:37 pm

Leave a reply

Name (*)
Mail (will not be published) (*)
URI
Comment