My favorites | Sign in
Project Home Downloads Wiki Issues Source
Search
for
FAQ  
Frequently Asked Questions.
Updated Nov 18, 2011 by ymkin....@gmail.com

Frequently Asked Questions

Typical Grid and Debug tools

In these examples, we use a typical Grid:

var myFlex = { 
    autoload    : false, 
    dataType    : 'json', 
    url         : 'grid.php', 
    usepager    : true 
}; 

$('#grid01').flexigrid($.extend({}, myFlex, { 
    colModel    : [ 
        {name: 'name',   display: 'NAME',   sortable: true}, 
        {name: 'status', display: 'STATUS', sortable: true}, 
        {name: 'sign',   display: 'SIGN',   sortable: true} 
    ]
})); 

For debug we use console.log() more likely than alert(), which is not always work as expected.

Examples

Dynamic columns and Post parameter to server

Colmodel define in variable. Parameters send to server by .flexOptions() on onSubmit().

var colModel01 = [ 
        {name: 'name',   display: 'NAME',   sortable: true}, 
        {name: 'status', display: 'STATUS', sortable: true}, 
        {name: 'sign',   display: 'SIGN',   sortable: true} 
]; 

$('#grid01').flexigrid($.extend({}, myFlex, { 
    colModel    : colModel01, 
    onSubmit    : function(){ 
        $('#grid01').flexOptions({params: [ 
            {name:'colls', value: $.param({colls: $.map(colModel01, function(elem,id){return elem.name}) }) } 
        ]}); 
        return true; 
    } 
})); 

In this code we post to server on load next data (with column names):

page=1&rp=15&sortname=undefined&sortorder=undefined&query=&qtype=& 
colls=colls%255B%255D%3Dname%26colls%255B%255D%3Dstatus%26colls%255B 
%255D%3Dsign 

Get selected row

The difficulty lies in linking: column_name - data. That is why the order of columns can be changed, and we can not use index in the array of row cells. In flexigrid-1.1 we have the attribute 'abbr' for sortable table cells (issue 46).

$('#grid01').click(function(event){
    $('.trSelected', this).each( function(){
        console.log(
            '  rowId: '  + $(this).attr('id').substr(3) +
            '  name: '   + $('td[abbr="name"] >div', this).html() +
            '  sign: '   + $('td[abbr="sign"] >div', this).html() +
            '  status: ' + $('td[abbr="status"] >div', this).html() 
        );
    });
});

Mouseclick and other events

As of jQuery 1.7, the .on() method provides all functionality required for attaching event handlers.

$('.flexigrid').on('mouseenter', 'tr[id*="row"]', function(){
    console.log('mouseenter rowId: ' + $(this).attr('id').substr(3));
});

With older jQuery: If we bind the event to the cells, we have to use the .live() or .delegate(). Because it when receiving data grid content is recreated.

$('.flexigrid tr[id*="row"]').live('mouseenter', function(){
    console.log('mouseenter rowId: ' + $(this).attr('id').substr(3));
});

Multiple filters

Just add a custom filter form

<form id="fmFilter"> 
    <input id="fmFilterSel1" name="fmFilterSel1" type="checkbox" /> 
    <input id="fmFilterSel2" name="fmFilterSel2" type="checkbox" /> 
    <input id="fmFilterSel3" name="fmFilterSel3" type="text" /> 
</form> 
<table id="grid01"><tr><td></td></tr></table> 

<script> 
$('#grid01').flexigrid($.extend({}, myFlex, { 
    onSubmit : function(){
        $('#grid01').flexOptions({params: [{name:'callId', value:'grid01'}].concat($('#fmFilter').serializeArray())});
        return true;
    } 
}); 
</script> 

And you send to server the filter condition of any complexity.

Format cells

You can colorize the cells, and even change the output according to the received data.

function gridFormat() { 
    var lblStatus = { 
        '101' : { 
            css : '', 
            txt : 'STATUS_OK' 
        }, 
        '102' : { 
            css : 'cellDisable', 
            txt : 'STATUS_LOCK' 
        }, 
        '103' : { 
            css : 'cellWarning', 
            txt : 'STATUS_BAD' 
        } 
    }; 
    $('#grid01 tr').each( function(){ 
        var cell = $('td[abbr="status"] >div', this); 
        $(this).addClass( lblStatus[cell.text()].css ); 
        cell.text( lblStatus[cell.text()].txt ); 
    }); 
    return true; 
}

$('#grid01').flexigrid($.extend({}, myFlex, { 
    buttons     : [
        {name: 'CLEAR', onpress: function(com,grid){ $('#grid01').flexAddData({rows:[],page:0,total:0}); }},
        {name: 'FILL',  onpress: function(com,grid){ $('#grid01').flexAddData({rows:[
            {id:'id0',cell:['name00',101,'A']},
            {id:'id1',cell:['name01',102,'B']},
            {id:'id2',cell:['name02',103,'C']}
        ],page:1,total:3}); }}
    ],
    onSuccess   : gridFormat 
}); 

In this example, the Grid has a buttons for fill/clear the test data. In column "status" we provide text labels for numeric values. Keep in mind that 'abbr' implemented in sortable columns only (#Get_selected_row).

Comment by marius.c...@gmail.com, Oct 12, 2011

Select row by ID:

$('.trSelected', this).each(function () {
$(this).removeClass('trSelected');
}); $("#row" + Id).toggleClass('trSelected');
Comment by shan2005...@gmail.com, Oct 20, 2011

How to add hyperliked values in flexigrid cells? Please suggest.

Comment by aji4...@gmail.com, Nov 7, 2011

Hi,

I have within a popup flexigrid. I am not able to dynamically add a column to the flexigrid based on some condition..

any suggestion on how to go ahead with this?

Comment by kni...@gmail.com, Nov 8, 2011

Sorry, I'm new in this and I could use the grid without any problem, but I have one question, How can I put the images in the buttons? because the the words (add, edit and delete) appear alone.

Comment by project member ymkin....@gmail.com, Nov 10, 2011

shan2005india, aji4all, knio16, wellcome to forum http://groups.google.com/group/flexigrid/browse_thread/thread/75ab9783ce684e56

Comment by ggmmaal...@gmail.com, Dec 21, 2011

how can I contribute to this project ? Is there some agreement for me to sigh?

Comment by hernanch...@gmail.com, Dec 21, 2011

Guys dont continue with this component I have may issues for monts its better Kendo UI Framework its the best solution http://demos.kendoui.com/web/grid/index.html

Comment by Filipe...@gmail.com, Dec 29, 2011

I need a hint, i'm using this "library" to query a DB and it's working very nice, great code guys.

But i need a little hint, i want to be able to select a row with a mouse click a "expand" the results on the same page on a "div" or something like it.

I have the code working showing the results with the "console.log" debugging, but i can't use it to show on a page :( Can someone help? Thanks

Comment by hernanch...@gmail.com, Dec 29, 2011

this code will help you $('#flex1').click(function(event){

$('.trSelected', this).each( function(){
var trace = ' rowId: ' + $(this).attr('id').substr(3) +
' iso: ' + $('td[abbr="iso"] >div', this).html() + ' name: ' + $('td[abbr="name"] >div', this).html() + ' printable_name: ' + $('td[abbr="printable_name"] >div', this).html();
alert(trace);
});
});

Comment by bharatja...@gmail.com, Feb 24, 2012

A

Comment by markelor...@gmail.com, Mar 21, 2012

I'm wondering how to clear the search field value when it is hidden. See http://stackoverflow.com/questions/9742293/jquery-flexigrid-search-value-not-cleared

Thanks for any help. Mark

Comment by markelor...@gmail.com, Mar 21, 2012

For some reason, there are no icons for add, edit, or delete on my flexigrid. I have:

		buttons : [
			{name: 'Add', 	 bclass: 'add_small',	onpress : takeAction},
			{name: 'Edit', 	 bclass: 'edit',   	onpress : takeAction},
			{name: 'Delete', bclass: 'delete', 	onpress : takeAction},
			{separator: true}
			],

and image files (tried different types) for the each of the bclass above. The online examples have icons, but there aren't any images included with the flexigrid download.

Can you help?

Comment by shahzeb...@gmail.com, Mar 28, 2012

u can find a concise thread to extend the flexigrid http://eaziweb.blogspot.com/2011/09/extend-flexigrid.html

Comment by susana.c...@gmail.com, Apr 2, 2012

Hi,

How can I make the table unscrollable? I want it to have some specific width and height, resizable is set to false, but still it scrolls. I want to use the pager only to get to the next available records.

Thanks!

Susana

Comment by susana.c...@gmail.com, Apr 2, 2012

Hi,

One more question, is it possible to have a column in the column model which is not visible? I wanted to have an id of some record available, but I don't want to show it in the page.

Thanks again,

Susana

Comment by tunat...@gmail.com, Apr 2, 2012

Yes it is possible;

{display: 'Row ID', name : 'id', width : 100, sortable : true,
align: 'left', hide: true},

Comment by afnfu...@gmail.com, Apr 5, 2012

Hello guys

I use this code to do action on single click

$('.flexme3').on('click', 'tr[id="row"]', function(){
var id= $(this).attr('id').substr(3); alert(id);
});
I want to do the same but on double click (not single click) ?

Comment by umeshsin...@gmail.com, Apr 9, 2012

Hello All

i am using dynamic html table and filling data to it dynamically using Linq List it is working good but my pager is not working plz help me and i am trying to fix i text box on top of each coulmn just below the header to use as filter i set the text box well, but now i dont know how to connect it to data to use as filter please help me umeshsinghgarg@gmail.com

Comment by hugo_wij...@hotmail.com, Apr 18, 2012

Hi there,

I need to figure out how to format the date in a column that is NOT flexigrids id. I followed the code below to see if I could reach a cell“s value. I do get the rowID as the correct value, but all other values are returned "null". All columns are sortable.

Any suggestions?

((( $('#flex1').click(function(event){

$('.trSelected', this).each( function(){
alert(
' rowId: ' + $(this).attr('id').substr(3) + ' name: ' + $('td[abbr="name"] <div', this).html() + ' iso: ' + $('td[abbr="iso"] >div', this).html() + ' printable_name: ' + $('td[abbr="printable_name"] >div', this).html()
);
});
});


Sign in to add a comment
Powered by Google Project Hosting