English 中文(简体)
How to specify the width of a slick grid in percentage?
原标题:

Is anybody knows how to set width of the grid in percentage?

for example but in the page the width of grid is more than 2000 pixels. It does not get adjusted to page width.

Any help would be appreciated.

Thanks Padmanabhan

问题回答

i see that this question is really old, but i came across this question while trying to figure out how to get my columns to take up the full width of the table. hopefully it ll help someone someday.

i couldn t figure out how to set the column widths explicitly but i did get it to work implicitly.

here s how to do it:

first in your column declaration add width: 300 (or whatever width you want)

{id:"name", name:"Student Name", field:"firstName", width: 300}

set this for all your columns, the ones you want wider put a bigger number, e.g. 500

then in your options declation add forceFitColumns: true

{enableCellNavigation: true, enableColumnReorder: false, forceFitColumns: true};

by doing this i was able to get my table columns to take up the remaining space of the table, and maintain the portions i want relative to each other.

I have a function to do a grid resize.

    function resizeGrid(newsize, grid) {
            $( #dataGrid ).css( width , newsize);
            grid.resizeCanvas();
    }

Don t forget to add forceFitColumns: true to your grid options as conman says above

FYI, this appears to work out of the box in recent versions of SlickGrid. :)

Yes, it is possible, but I can not find an easy solution. So you have to customize it quite a bit.

I am currently working on a solution for this. Here is a working example, but it does have a few bugs. Some of which are from jsfiddle setup. http://jsfiddle.net/MQBLn/8/

basically I created a function that formats the cells based on the Column Heading Sizes. Then you have to call that function whenever there is an Action. (Sort, Resize, Etc.) Also I did have to make some minor changes to slick.grid.js So you will find it loaded at the top of JS section followed by custom js. Then some overwrite rules for css.

Here is my Cell Formatter Function

function formatCells(grid)
{
    var columns = grid.getColumns();
    var grid_width = grid.getGridPosition().width;
    var header = $(".slick-header-columns");

    for(var i in columns)
    {
        $(".slick-cell.r"+i).css("width", (Math.floor(((header.children().eq(parseFloat(i)).width()+9)/(grid_width-_scrollBarWidth))*10000)/100)+"%");
    }
}

I hope this is usefull and maybe one day built into SlickGrid as a setting.

The SlickGrid-formatter supply you with 5 parameters:

formatter: function ( row, cell, value, columnDef, dataContext )

You can adjust the columns width using the dataContext parameter, within the specific formatter, etc: dataContext.width = 600 makes the specific column 600px.

Example

    {
        /* Categories */
        id: "categories",
        formatter: function ( row, cell, value, columnDef, dataContext ) {
            var html =   ;

            if ( value.indexOf(  variation-child  ) != -1 ) {
                return value;
            } else if ( value ) {
                for ( var i = 0; i < value.length; i++ ) {
                    if ( value[ i ] ) {
                        html +=  <div class="box category-box" title="  + value[ i ] +  ">  + value[ i ] +  </div> ;
                    }
                }
            }

            columnDef.width = 600 * value.length;

            return html;
        },
        name: "Categories", field: "categories", sortable: true, editor: Slick.Editors.TaxonomyPopupEditor
    }

Remember to use grid.resizeCanvas(); (recalculate the widths), whenever you re done adding data to the grid.





相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签