flexigrid examples returning data from mysql

Jason Spick picture Jason Spick · Jun 17, 2011 · Viewed 11.7k times · Source

I'm sure it can be done, I just need to see some examples. I want to use flexigrid to show massive sets of data stored in mysql. I am proficient in php, but new to jquery and json.

Can anyone point me in the right direction or provide a good example? I need to see how to return data back to the flexigrid json.

Thank you

Great Tutorial on this topic

Answer

JoeyH picture JoeyH · Jun 17, 2011

This is just the partial code for returning your database results, you would call you page with the flexigrid jquery code

        while ($row = mysql_fetch_assoc($results)) {
         $data['rows'][] = array(
                                  'id' => $row['pf_id'],
                                  'cell' => array(
                                               $row['cat_code'], 
                                               $row['cat_title'], 
                                               $row['cat_link'] = "<a href=\"catagory_edit.php?cat_id=".$row['cat_id']."\">Edit</a> | <a href=\"catagory_to_family_association.php?cat_id=".$row['cat_id']."\">Associate Familys</a> | <a href=\"category_child_order.php?cat_id=".$row['cat_id']."\">Order Children</a>")); }
echo json_encode($data);

call the page with the flexigrid jquery code

$("#flex1").flexigrid({
            url: 'category_main_json.php',
                        dataType: 'json',
                        colModel : [
                            {display: 'Code', name : 'cat_code', width : 70, sortable : true, align: 'left'},
                            {display: 'Name', name : 'cat_title', width : 550, sortable : true, align: 'left'},
                            {display: 'Action', name : 'cat_link', width : 205, sortable : true, align: 'left'},
                            ],
                        buttons : [
                            {name: 'Add New Category', bclass: 'add', onpress : test},
                            {separator: true}
                            ],
                        searchitems : [
                            {display: 'Code', name : 'cat_code'},
                            {display: 'Name', name : 'cat_title', isdefault: true}
                            ],
                        sortname: "cat_code",
                        sortorder: "asc",
                        usepager: true,
                        useRp: true,
                        rp: 50,
                        showTableToggleBtn: false,
                        resizable: false,
                        width: 880,
                        height: 450,
                        singleSelect: true,
                        showTableToggleBtn: false

                    }
                );