Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to set column width? #226

Open
YannisMarios opened this issue Feb 23, 2018 · 38 comments
Open

How to set column width? #226

YannisMarios opened this issue Feb 23, 2018 · 38 comments

Comments

@YannisMarios
Copy link

Hi,

I am trying to set the column width? How do you do It with react-bootstrap-table2?

@AllenFang
Copy link
Member

@YannisMarios #221

This is not implemented yet. I will enhance this feature ASAP, thanks.

@waynebrantley
Copy link

waynebrantley commented Mar 5, 2018

@AllenFang Trying to convert to your new version. Ran into this same issue - pretty much blocking us at this point. I was able to use headerStyle to set the width for now. Maybe that is the new way?

@AllenFang
Copy link
Member

@waynebrantley right now, headerStyle is just a way, I'm think other good solution for it. I apologize for this inconvenience

@Northshoot
Copy link

I think current implementation if great!

Just add to your column description and done.

 headerStyle: (colum, colIndex) => {
          return { width: '80px', textAlign: 'center' };
        }

@waynebrantley
Copy link

@AllenFang so is headerStyle going to be how this is done? That is fine, might should put a storybook showing?

@nthgol
Copy link
Contributor

nthgol commented Jul 16, 2018

can anyone suggest a way to 'width - auto' size the columns according to the data?

@AlessandroGambaro
Copy link

<BootstrapTable....>
<TableHeaderColumn width={'20%'} ....
<TableHeaderColumn width={'80%'} ...

@pceccato
Copy link

pceccato commented Oct 3, 2018

Is there an example of how to set the column widths? This is fundamental functionality...

@waynebrantley
Copy link

@pceccato See @Northshoot comment above...that is part of the column definition...works good.

@pceccato
Copy link

pceccato commented Oct 4, 2018

Does it need to be an arrow function?

@B-R-Bender
Copy link

B-R-Bender commented Dec 20, 2018

Does it need to be an arrow function?

No, you could use anonymous function declaration. Or any other you may like.

@JenniferMarston
Copy link

Hi. I'm just starting to use the component, but the proposed does not work if we want the table to be responsive.

@ehtasham89
Copy link

how to set width in react-bootstrap-table2
let columns = [ { dataField: 'lastModified', text: 'Last Modified Date', width: "60" }, ]

Its not working...

@JenniferMarston
Copy link

JenniferMarston commented Jan 6, 2019 via email

@lovato
Copy link

lovato commented Mar 12, 2019

Response is above: #226 (comment)
It works.

@mhdfaisal
Copy link

I think current implementation if great!

Just add to your column description and done.

 headerStyle: (colum, colIndex) => {
          return { width: '80px', textAlign: 'center' };
        }

It works

@Maneeshachandran
Copy link

Hi,
I am trying to increase the width of some particular columns. Adding style to the column description doesn't help. How to achieve my requirement?

@Shannibrst
Copy link

Shannibrst commented Apr 25, 2019

Hello, Same problem how to set column width?
above examples, not works for me

Thanks

@lovato
Copy link

lovato commented Apr 26, 2019

@Maneeshachandran and @Shannibrst ... can you share a few code snippets?

@Maneeshachandran
Copy link

@lovato I need to increase the width of the first column. So I have used the style. But it is not working.
var Columns = [
{
dataField: "description",
text: "Description",
editable: false,
style:{
width: '10%'
}
},
{
dataField: "deliverableSatus",
text: "Deliverable Status",
editor: {
type: Type.SELECT,
options: [
{
value: "Complete",
label: "Complete"
},
{
value: "Incomplete",
label: "Incomplete"
},
{
value: "N/A",
label: "N/A"
}
]
}
}
]

@lovato
Copy link

lovato commented Apr 26, 2019

@Maneeshachandran have you tried previous responses? That worked for me, and it is different from your approach.
Try:

var Columns = [
  {
    dataField: "description",
    text: "Description",
    editable: false,
    headerStyle: () => {
      return { width: "10%" };
    }
  },
  {
    dataField: "deliverableSatus",
    text: "Deliverable Status",
    editor: {
      type: Type.SELECT,
      options: [
        {
          value: "Complete",
          label: "Complete"
        },
        {
          value: "Incomplete",
          label: "Incomplete"
        },
        {
          value: "N/A",
          label: "N/A"
        }
      ]
    }
  }
];

@Maneeshachandran
Copy link

@lovato Hi Lovato.. It is working for a simple table. Whereas in my case, I need to implement it for a large table. I have vertical and horizontal scroll bars for the table. For this table, I cannot able to fix the column width.

@lovato
Copy link

lovato commented Apr 29, 2019

@Maneeshachandran Sorry, but w/o code for this "large table", I can't understand the problem. I am using it across two projects, different table sizes, several tables, and everything is running smooth.

@davidsonsns
Copy link

I just followed this reference and it worked for me react-bootstrap-table2 storybook Work on Header Columns - Customize Column Style

@almog-kiki
Copy link

.react-bootstrap-table th[data-row-selection] {
width: 40px !important;
}

@AlexPuga
Copy link

AlexPuga commented Sep 11, 2019

css

.react-bootstrap-table {
display: block;
width: 100%;
overflow-x: auto;
-webkit-overflow-scrolling: touch
}
.react-bootstrap-table table {
table-layout: auto !important
}
.table th,
.table td {
white-space: nowrap
}

Table Rows Options:
headerStyle:{minWidth: '200px'}

@ddouglas
Copy link

I have no doubt that all of these solutions work flawlessly, however I am hiding the header row:

        {
            headerStyle: () => {
                return { width: "70%" };
            },
            dataField: "name",
            text: "Name",
            headerAttrs: {
                hidden: true
            },
            formatter: (_, row) => {
                return (
                    <div>
                        <Image
                            src={IMAGE_URL + `/alliance/` + row.id + `_32.png`}
                            rounded
                            fluid
                            className="mr-3"
                        ></Image>
                        <LinkContainer to={`/alliances/` + row.id}>
                            <a>{row.name}</a>
                        </LinkContainer>
                    </div>
                );
            }
        },

and due to this none of the proposed solutions are working. I can even see the classes being applied using Chrome Dev Tools. The issue, for me, is the default style applied to the wrapper class:

.react-bootstrap-table table {
    table-layout: fixed;
}

Using dev tools, if I remove that class, the table width adopts the values of the width parameters passes via to BS Tables. I need away to remove this class via the library. I have tried passing in null and a blank string to no avail.
I also apologize because I am not that savy with CSS and I am just learning React, so please excuse any ignorance. I have also read the documentation and could not find a solution.

Thank You.

@awitherow
Copy link

is this going to be done (been about a year now) or just hacked?

@Guiw5
Copy link

Guiw5 commented Nov 12, 2019

@AllenFang @YannisMarios
I think it should be closed as it's solved by an alternative way to do it.
...as we said "it's not an issue is a feature"

@ddouglas
Copy link

ddouglas commented Nov 12, 2019

Add the bootstrap4 property and the header overrides I meantion above take effect.

@dotjrt dotjrt mentioned this issue Nov 14, 2019
@Nandiniyadavraj
Copy link

hello there,
I checked on all possible way to increase column width as mentioned above but none of it work for me.

          headerStyle: (colum, colIndex) => {
                return { 'white-space': 'nowrap', width: '100px' };
            }

with the help of this code I'm able to manage table header column size but not table cells size.
Even I applied css also on table ... help me out if any of you had solved this issue.

Thanks.

@AlexPuga
Copy link

AlexPuga commented May 4, 2020

Try it:
formatter: (col, row) => { return <span style={{display: 'block', width: 100, overflow: 'hidden', whiteSpace: 'nowrap', textOverflow: 'ellipsis'}}>{col}</span> }

@Nandiniyadavraj
Copy link

It's really working. Thank you so much @AlexPuga

@ChaitraK2000
Copy link

Hi I am trying React-bootstrap-table. But i wanted to increase the width of header row. How can i do that?

@yousefshakoury
Copy link

I think current implementation if great!

Just add to your column description and done.

 headerStyle: (colum, colIndex) => {
          return { width: '80px', textAlign: 'center' };
        }

Thanks

@Sharmistha24
Copy link

Try this.
{
dataField: 'about',
text: 'About',
headerStyle: () => {
return { minWidth: '200px' };
}
}

@tushar681
Copy link

Hi there,
I am facing issue because I am using a table without header, it is hidden as below:
headerAttrs: {
hidden: true
}
As it is hidden, so my headerStyle is not working on it.
Is there any way, I can set width of table column without headerStyle and only using style :{} attribute or any other way.

Thanks in advance

@istiak227
Copy link

Try it:
formatter: (col, row) => { return <span style={{display: 'block', width: 100, overflow: 'hidden', whiteSpace: 'nowrap', textOverflow: 'ellipsis'}}>{col}</span> }

if nothing works, try this one. Worked for me. Cheers!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests