react-bootstrap-table2 icon indicating copy to clipboard operation
react-bootstrap-table2 copied to clipboard

How to set column width?

Open YannisMarios opened this issue 7 years ago • 38 comments

Hi,

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

YannisMarios avatar Feb 23 '18 03:02 YannisMarios

@YannisMarios https://github.com/react-bootstrap-table/react-bootstrap-table2/issues/221

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

AllenFang avatar Feb 23 '18 06:02 AllenFang

@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?

waynebrantley avatar Mar 05 '18 19:03 waynebrantley

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

AllenFang avatar Mar 06 '18 16:03 AllenFang

I think current implementation if great!

Just add to your column description and done.

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

Northshoot avatar Mar 24 '18 18:03 Northshoot

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

waynebrantley avatar May 31 '18 13:05 waynebrantley

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

nthgol avatar Jul 16 '18 21:07 nthgol

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

AlessandroGambaro avatar Aug 01 '18 13:08 AlessandroGambaro

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

pceccato avatar Oct 03 '18 11:10 pceccato

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

waynebrantley avatar Oct 03 '18 18:10 waynebrantley

Does it need to be an arrow function?

pceccato avatar Oct 04 '18 10:10 pceccato

Does it need to be an arrow function?

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

B-R-Bender avatar Dec 20 '18 13:12 B-R-Bender

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

JenniferMarston avatar Dec 20 '18 21:12 JenniferMarston

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

Its not working...

ehtasham89 avatar Jan 06 '19 14:01 ehtasham89

Try adding 60px instead.

That should work, but then the table loses its responsive behavior.

On Sun, Jan 6, 2019 at 9:19 AM Ethasham Nasir [email protected] wrote:

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

Its not working...

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/react-bootstrap-table/react-bootstrap-table2/issues/226#issuecomment-451745172, or mute the thread https://github.com/notifications/unsubscribe-auth/AJIgLu9-XTfSVcTzGq7Rqs7tEMTzTwQWks5vAgYNgaJpZM4SQUTB .

JenniferMarston avatar Jan 06 '19 14:01 JenniferMarston

Response is above: https://github.com/react-bootstrap-table/react-bootstrap-table2/issues/226#issuecomment-375913180 It works.

lovato avatar Mar 12 '19 23:03 lovato

I think current implementation if great!

Just add to your column description and done.

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

It works

mhdfaisal avatar Mar 24 '19 15:03 mhdfaisal

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?

Maneeshachandran avatar Apr 11 '19 09:04 Maneeshachandran

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

Thanks

Shannibrst avatar Apr 25 '19 12:04 Shannibrst

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

lovato avatar Apr 26 '19 01:04 lovato

@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" } ] } } ]

Maneeshachandran avatar Apr 26 '19 06:04 Maneeshachandran

@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"
        }
      ]
    }
  }
];

lovato avatar Apr 26 '19 18:04 lovato

@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.

Maneeshachandran avatar Apr 29 '19 05:04 Maneeshachandran

@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.

lovato avatar Apr 29 '19 14:04 lovato

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

davidsonsns avatar Jul 17 '19 12:07 davidsonsns

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

almog-kiki avatar Jul 29 '19 11:07 almog-kiki

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'}

AlexPuga avatar Sep 11 '19 06:09 AlexPuga

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.

ddouglas avatar Oct 26 '19 20:10 ddouglas

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

awitherow avatar Oct 30 '19 22:10 awitherow

@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"

Guiw5 avatar Nov 12 '19 15:11 Guiw5

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

ddouglas avatar Nov 12 '19 15:11 ddouglas