Part of the EllisLab Network
   
34 of 68
34
Flexigrid - Lightweight but rich data grid
Posted: 20 May 2008 11:48 AM   [ Ignore ]   [ # 331 ]  
Summer Student
Total Posts:  24
Joined  05-11-2008

paulopmx - thanks for the response. Although my main problem was that nothing was showing up in firebug to trace anything. So, no errors were occurring.

However, I was able to find the root of the problem. This is just for anyone else who would want to know - the problem was with prototype. I had a prototype library being loaded. I did have the jquery noConflict mode on but for some reason, it still did not want to cooperate with Flexigrid. If anyone knows a way to have prototype and Flexigrid working together, that would be great.

For now, I have just removed the prototype reference and have been working around it.

Profile
 
 
Posted: 20 May 2008 03:48 PM   [ Ignore ]   [ # 332 ]  
Summer Student
Total Posts:  4
Joined  05-20-2008
ecarsted - 08 April 2008 10:22 PM

Hey Paulo,

$('#flex1').flexOptions({newp:1}); 

Fixed my paging problem.

A couple questions for you.

1) Is it possible to set the table to only select one row?
2) How do I add an event to a row being selected/deselected?

i’ve modifed the flexigrid.js to fire a onRowSelected event that passes the id of the row, the actual row and the grid. it was suprisingly easy to implement.

i’m going to look at creating a ‘multi-select’ and ‘single-select’ option - (time permitting).

[edit]

wow thanks to Paulo’s excellent work - implementing a singleSelect was so easy. if anyone is interested reply and i’ll post the code here.

regards
Sean

Profile
 
 
Posted: 20 May 2008 07:46 PM   [ Ignore ]   [ # 333 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  169
Joined  04-23-2007
swhitlow - 20 May 2008 03:48 PM

paulopmx - thanks for the response. Although my main problem was that nothing was showing up in firebug to trace anything. So, no errors were occurring.

However, I was able to find the root of the problem. This is just for anyone else who would want to know - the problem was with prototype. I had a prototype library being loaded. I did have the jquery noConflict mode on but for some reason, it still did not want to cooperate with Flexigrid. If anyone knows a way to have prototype and Flexigrid working together, that would be great.

For now, I have just removed the prototype reference and have been working around it.

This must be the same problem encountered with mootools, where mootools is ‘extending’ all native objects and methods. I will look in to this in my next release.

 Signature 

A Better and more Flexible Paging Solution for CI
Automatic config[base_url]

Profile
 
 
Posted: 20 May 2008 07:48 PM   [ Ignore ]   [ # 334 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  169
Joined  04-23-2007
SeanRock - 20 May 2008 07:48 PM
ecarsted - 08 April 2008 10:22 PM

Hey Paulo,

$('#flex1').flexOptions({newp:1}); 

Fixed my paging problem.

A couple questions for you.

1) Is it possible to set the table to only select one row?
2) How do I add an event to a row being selected/deselected?

i’ve modifed the flexigrid.js to fire a onRowSelected event that passes the id of the row, the actual row and the grid. it was suprisingly easy to implement.

i’m going to look at creating a ‘multi-select’ and ‘single-select’ option - (time permitting).

[edit]

wow thanks to Paulo’s excellent work - implementing a singleSelect was so easy. if anyone is interested reply and i’ll post the code here.

regards
Sean


Great job Sean.

jQuery is pretty easy just like CodeIgniter.

 Signature 

A Better and more Flexible Paging Solution for CI
Automatic config[base_url]

Profile
 
 
Posted: 20 May 2008 08:33 PM   [ Ignore ]   [ # 335 ]  
Summer Student
Total Posts:  5
Joined  05-20-2008

Hello all. I’ve been fascinated by this plugin for the last couple of days and I stumbled into this forum. I took some existing code I’ve been using and modified it for a very straight forward example of the use of this awesome plugin with CI. Excellent work Paulo!
The DB

<?php   // CREATE TABLE `dbname`.`homes` (
    // `id` INT( 10 ) NOT NULL AUTO_INCREMENT ,
    // `price` FLOAT( 14 ) NOT NULL ,
    // `sqft` FLOAT( 10 ) NOT NULL ,
    // `bedrooms` INT( 2 ) NOT NULL ,
    // `pool` INT( 1 ) NOT NULL ,
    // `description` VARCHAR( 250 ) NOT NULL ,
    // PRIMARY KEY ( `id` )
    // ) ENGINE = MYISAM 
?> 

The Model
homesmodel.php

<?php
class Homesmodel extends Model {




    
function __construct() {
        parent
::Model();
    
}

/* RETURNS AN ARRAY WITH TWO ITEMS
        'homes'=> THE RESULT OBJECT     
        'total'=> NUMBER OF TOTAL RESULTS OF THE QUERY WITHOUT LIMIT AND OFFSET */

    
function fetch_homes($sortname='price',$sortorder='desc',$limit=10,$offset=1,$query=null,$qtype=null{

    $this
->db->from('homes');
    
$this->db->order_by($sortname,$sortorder);
    
    if(! 
is_null($query)) {
    
        
/* GET TOTAL ROWS BEFORE THE LIMIT */
        
$this->db->like($qtype,$query);
        
$total $this->db->get()->num_rows();
        
        
/* RESET THE DB QUERY SINCE IT WAS ALREADY USED */
        
$this->db->like($qtype,$query);
    
}
    
    
else {//NO QUERY
    
$total $this->db->get()->num_rows();
    
}
        
/* RESET THE DB QUERY*/
        
$this->db->from('homes');
        
$this->db->order_by($sortname,$sortorder);
        
$this->db->limit($limit,$offset);
        
$q $this->db->get();
        
$arr = array('homes'=>$q,'total'=>$total);
        return 
$arr;
}
    
}
?> 

The View
view_homes.php

<?php 
/* CODE IGNITER, JQUERY FLEXIGRID DEMO
WITH JSON TABLE UPDATING AND SEARCH */

/* LOAD THE FLEXIGRID STYLESHEET */
echo link_tag('css/flexigrid.css');
echo 
link_tag('css/homes.css');?>


<!-- THE FLEXIGRID TABLE -->
<
table id="flexigrid_homes"></table>

<!-- 
LOAD JQUERY AND FLEXIGRID -->




<!-- 
script-->
    
function 
alertSelected() {
    
var alert_text '';
    var 
selected_rows = $("table#flexigrid_homes").find("tr.trSelected").get();
    if(
selected_rows.length 0{
        alert_text 
'You selected the following row ids:' ;
    
}
    
else {
        alert_text 
'You did dnot select any rows';
    
}
    
$.each(selected_rows,function(i,n{
        
var id = $(n).attr("id");
        
alert_text += id.substr(3)+", ";
    
});
    
alert(alert_text);
    
/* console.log(alert_text); */
}

function selectAll() {
    
var rows = $("table#flexigrid_homes").find("tr").get();
    if(
rows.length 0{
    
$.each(rows,function(i,n{
        
$(n).addClass("trSelected");
    
});
    
}
}

function deselectAll() {
    
var selected_rows = $("table#flexigrid_homes").find("tr").get();
    if(
selected_rows.length 0{
    
$.each(selected_rows,function(i,n{
        
$(n).removeClass("trSelected");
    
});
    
}
}

function invertSelection() {
    
var rows = $("table#flexigrid_homes").find("tr").get();
    $.
each(rows,function(i,n{
        
$(n).toggleClass("trSelected");
    
});
}

function bind_single_select() {
  
if ( ! $("input#single").length>0{
    
$("span.single_select").prepend("<input type='checkbox' name='single' id='single' />");
  
}
$("table#flexigrid_homes").find("tr").click(function() {
        
if($("input#single").attr("checked")) {
            
$(".trSelected").removeClass("trSelected");
            $(
this).addClass("trSelected");
        
}
        }
);
}
$(document).ready(function() {
            
$("table#flexigrid_homes").flexigrid({
            url
'/CI_BASE/index.php/homes/flex',
            
dataType'json',
            
colModel [
                {display
'Id'name 'id'width 40sortable truealign'left'},
                
{display'Description'name 'description'width 300sortable truealign'left'},
                
{display'Price'name 'price'width 100sortable truealign'left'},
                
{display'Square Footage'name 'sqft'width 100sortable truealign'right'},
                
{display'Bedrooms'name 'bedrooms'width 100sortable truealign'right'},
                
{display'Pool'name 'pool'width 30sortable truealign'center'},
                
],
            
searchitems [
                {display
'Description'name 'description'isdefaulttrue},
                
],
            
buttons [
                {name
'Alert Selected'bclass'alert_selected',onpressalertSelected},
                
{separatortrue},
                
{name'Select All'bclass'alert_selected',onpressselectAll},
                
{name'Deselect All'bclass'alert_selected',onpressdeselectAll},
                
{name'Invert Selection'bclass'alert_selected',onpressinvertSelection},
                
{separatortrue},
                
{name'Single Select'bclass'single_select',onpressbind_single_select},
                
],
            
sortname"price",
            
sortorder"desc",
            
usepagertrue,
            
title'Homes',
            
procmsg"Searching the MASSIVE homes database",
            
useRptrue,
            
rp5,
            
rpOptions[5,10,20,50],
            
showTableToggleBtntrue,
            
height'150',
            
onSuccessbind_single_select
        }
);

}); 

Next post the Controller

Profile
 
 
Posted: 20 May 2008 08:42 PM   [ Ignore ]   [ # 336 ]  
Summer Student
Total Posts:  5
Joined  05-20-2008

The Controller
homes.php

<?php
class Homes extends Controller {
    
function __construct() {
        parent
::Controller();
        
        
/* LOAD THE HELPERS */
        
$this->load->helper(array('url','html'));
        
    
/* LOAD THE DATABASE FUNCTIONS */
        
$this->load->database();
        
$this->load->model('homesmodel');
    
}
    
    
public function index() {
        $this
->load->view('view_homes');//THE VIEW CONTAINING THE TABLE TO BE FLEXED
    
}
    
    
function flex() {//THE PUBLIC FUNCTION TO PRINT THE TABLE CONTENTS
        
if( ! $this->input->post('page')) {
            
echo "You shouldn't be here";
            
// redirect('homes');
        
}
        
else {
        $json 
=  $this->_populateFlexigrid();
        
        
//THE JSON ENCODED DATA
        
echo $json;
        
}
    }
    
    
    
function _populateFlexigrid() {
        
        header
("Content-type: text/x-json");    
        
        
/* GET THE POST */
        
$page $this->input->post('page');
        
$rowsPerPage $this->input->post('rp');
        
$sortname $this->input->post('sortname');
        
$sortorder $this->input->post('sortorder');
        
$query $this->input->post('query');
        
$qtype $this->input->post('qtype');
        
        
/* CHECK THE POST */
            
$sortname = ($sortname $sortname :  'id');//default sort
            
$sortorder = ($sortorder $sortorder 'desc');//default order
            
$page = ($page intval($page) : 1);
            
$rowsPerPage = ($rowsPerPage intval($rowsPerPage) : 10);
            
$query = ($query $query null);
            
$qtype = ($qtype $qtype null);
            
$start = (($page-1) * $rowsPerPage);

        
/* GET THE RECORDS BASED ON THE ARGUMENTS */
        
$items $this->homesmodel->fetch_homes($sortname,$sortorder,$rowsPerPage,$start,$query,$qtype);
            
$homes $items['homes'];
            
$total $items['total'];
            
        
/* THE ARRAY TO BE ENCODED WITH KNOWN VARIABLES*/
        
$json = array('page'=>$page'total'=>$total);
        
        foreach (
$homes->result() AS $home{
            
            
/* ADD AN ICON FOR THE POOL RESULT */
            
$pool = ($home->pool img('images/true.png') : '');
            
            
$json['rows'][] = array(
                        
'id'=>$home->id,
                        
'cell' => array($home->id,$home->description,"$ ".number_format($home->price,0),number_format($home->sqft,0),$home->bedrooms,$pool),
                    ); 
        
}
        
return json_encode($json);
    
}
    
Profile
 
 
Posted: 21 May 2008 05:08 AM   [ Ignore ]   [ # 337 ]  
Summer Student
Avatar
Total Posts:  12
Joined  04-04-2008

Hi, is it possible to add some sort of styling to a certain row on the flexigrid dynamically? I would like to change the background color of rows that have a certain value.

Profile
 
 
Posted: 21 May 2008 05:09 AM   [ Ignore ]   [ # 338 ]  
Summer Student
Total Posts:  8
Joined  05-20-2008
SeanRock - 20 May 2008 07:48 PM

wow thanks to Paulo’s excellent work - implementing a singleSelect was so easy. if anyone is interested reply and i’ll post the code here.

regards
Sean

ReplyReply snake

Indeed the Flexigrid is cool and Paulo did an excelent work. I have a solution for my problems, but it is not sophisticated. I am something like new at Javascript/DOM (usually I work with J2EE or PHP), but it is fascinating and sometimes strange and mindbogglingly cool smirk.
So it would be nice to see an implementation with events!


Holla

Profile
 
 
Posted: 21 May 2008 09:22 AM   [ Ignore ]   [ # 339 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  1509
Joined  06-05-2007

BTW Great thread guys…Paulo this would be good stuff to start a Wiki or Google Group with.

Is there any way to skip the PHP echo or ASP call which then converts it to XML and instead just pull a hard XML file outputted from an already established db?

Thanks!

 Signature 

Marshall Grant   |  grantmx.com  |  Atlanta, GA   |  design  |  development  |  @grantmx

Profile
 
 
Posted: 21 May 2008 10:07 AM   [ Ignore ]   [ # 340 ]  
Summer Student
Total Posts:  1
Joined  05-21-2008

Since this thread is getting so long, would the flexigrid Google code project at http://code.google.com/p/flexigrid/ be a better place to post bug reports and possibly submit patches.  Is that the future home of flexigrid?  Hosting the downloads there would probably really help out on bandwidth issues.

Thanks for the great component!

Profile
 
 
   
34 of 68
34