material-table icon indicating copy to clipboard operation
material-table copied to clipboard

How to adjust the width of the Material Table and how do I make the icons show up?

Open wangb-ctrl opened this issue 7 years ago • 22 comments

Right now my icons are now showing up as shown in screenshot below: screen shot 2019-02-26 at 9 02 43 pm would the code simply be:

<MaterialTable
     icons={
                { Search, NextPage }
                }
     columns={[....]}
 />

I tried doing so, but I got this error: image

In addition, is there a way to adjust the size of Material Table itself? I don't see a width/height prop.

Thank you so much in advance!

wangb-ctrl avatar Feb 27 '19 06:02 wangb-ctrl

Is there also a way to disable displaying: screen shot 2019-02-26 at 10 47 31 pm

wangb-ctrl avatar Feb 27 '19 06:02 wangb-ctrl

I also have a similar question. Is there a way to adjust the width of both the table itself and respective columns of the table?

vinceliu21 avatar Feb 28 '19 03:02 vinceliu21

@brittanywang for your question about displaying the Rows per page: <MaterialTable options={{ paging: false }} /> That did it for me.

JWLangford avatar Mar 01 '19 15:03 JWLangford

@JWLangford thank you!

wangb-ctrl avatar Mar 01 '19 22:03 wangb-ctrl

To set width of columns use both cellStyle and headerStyle:

{ title: 'Name', field: 'name',
     cellStyle: {
       width: 20,
       maxWidth: 20
     },
     headerStyle: {
       width:20,
       maxWidth: 20
     }
    },

mbrn avatar Mar 03 '19 18:03 mbrn

for table width you can cover table with a div that has its own width

mbrn avatar Mar 03 '19 18:03 mbrn

@mbrn thank you for your comments! I am still unable to display the icons. Do you have any suggestions? Do I have to import MaterialUI? Currently I'm using:

<MaterialTable
     icons={
                { Search, NextPage }
                }
     columns={[....]}
 />

Thank you for your time!

wangb-ctrl avatar Mar 03 '19 22:03 wangb-ctrl

@brittanywang How did you import icons Search and NextPage

mbrn avatar Mar 04 '19 04:03 mbrn

@mbrn forgot to close this, resolved in (#93). Many thanks again!

wangb-ctrl avatar Mar 04 '19 05:03 wangb-ctrl

when i set data table in container, it exceeds than container, how i fix this issue

indraneelpradhan avatar Oct 15 '19 12:10 indraneelpradhan

I had the same problem, but I solved as

cellStyle: { width: 300, minWidth: 300 }, headerStyle: { width: 300, minWidth: 300 }, ...

If you want to down size use maxWidth, but if you want to up size use minWidth

juliosilvacwb avatar Mar 06 '20 03:03 juliosilvacwb

Is there also a way to disable displaying: screen shot 2019-02-26 at 10 47 31 pm

in the options you can disable the pagination by using paging: false

options = {{
    paging: false
}}

royliu007 avatar May 29 '20 00:05 royliu007

but if you want to up size use minWidth

it's not working...

jaggaer-npasic avatar Oct 09 '20 12:10 jaggaer-npasic

but if you want to up size use minWidth

it's not working...

It's true, it doesn't work, but this does: Put width: 120 (or whatever value you need) as an attribute of the column, just like you do with title: "my title", width: 50, ... etc https://material-table.com/#/docs/features/fixed-columns

ghost avatar Nov 20 '20 16:11 ghost

This works for me.

With Gson in backend as json.

JsonDataKeys: simple enum to store names.

public static JsonObject getKeyCell() {
        JsonObject key = new JsonObject();
        key.addProperty(JsonDataKeys.title.name(), "Key");
        key.addProperty(JsonDataKeys.field.name(), JsonDataKeys.key.name());
        key.addProperty(JsonDataKeys.editable.name(), "never");

        JsonObject keyCellStyle = new JsonObject();
        keyCellStyle.addProperty("maxWidth", "200px");
        key.add("cellStyle", keyCellStyle);
        key.add("headerStyle", keyCellStyle);
        key.addProperty("width", "200px");
        return key;
    }

Strauteka avatar Dec 16 '20 05:12 Strauteka

It looks like the min value is 100. I tried cellStyle: { backgroundColor: '#bfbfbf', color: '#000000', width: 100, maxWidth: 100 }, headerStyle: { backgroundColor: '#bfbfbf', color: '#000000', width: 100, maxWidth: 100 } It only works for number above 100. Cannot go any lower.

RoosterH avatar Jan 03 '21 05:01 RoosterH

having the same here, if I put something below 100, it's doesn't work... so, I need a column for a "row number" that should be way smaller than the other fields... it isn't possible?

GersonDias avatar Jan 18 '21 16:01 GersonDias

To set width of columns use both cellStyle and headerStyle:

{ title: 'Name', field: 'name',
     cellStyle: {
       width: 20,
       maxWidth: 20
     },
     headerStyle: {
       width:20,
       maxWidth: 20
     }
    },

This one is not working for me

        `<MaterialTable
            icons={Common.tableIcons}
            title=""
            columns={[
              {
                field: "sNo",
                title: " S.No",
                headerStyle: {
                  fontWeight: "bold",
                  width: 2,
                  maxWidth: 2,
                },
                cellStyle: { width: 2, maxWidth: 2 },
              },
              {
                field: "downtimeId",
                headerStyle: { fontWeight: "bold" },
                title: "System Downtime ID",
              },

              {
                field: "startDateTime",
                title: "Start Date/ Time",
                headerStyle: { fontWeight: "bold" },
              },
              {
                field: "endDateTime",
                title: "End Date/ Time",
                headerStyle: { fontWeight: "bold" },
              },
              {
                field: "message",
                headerStyle: { fontWeight: "bold" },
                title: "Error Message",
              },
              {
                // field: "action",
                title: "Action",
                headerStyle: { fontWeight: "bold" },

                type: "text",
                render: (rowData) => (
                  <>
                    {" "}
                    <Link style={{ cursor: "pointer" }}>
                      {" "}
                      <EditIcon color="primary" fontSize="small" />{" "}
                    </Link>
                    <Link style={{ cursor: "pointer" }}>
                      {" "}
                      <DeleteIcon color="primary" fontSize="small" />{" "}
                    </Link>
                  </>
                ),
              },
            ]}
            options={{ exportButton: true, paginationType: "stepped" }}
            data={rows}
          ></MaterialTable>`

It doesn't reflect on screen. columns are still the same way they are.

jagadeeshkoka avatar Jan 28 '21 10:01 jagadeeshkoka

To set width of columns use both cellStyle and headerStyle:

{ title: 'Name', field: 'name',
     cellStyle: {
       width: 20,
       maxWidth: 20
     },
     headerStyle: {
       width:20,
       maxWidth: 20
     }
    },

This one is not working for me

        `<MaterialTable
            icons={Common.tableIcons}
            title=""
            columns={[
              {
                field: "sNo",
                title: " S.No",
                headerStyle: {
                  fontWeight: "bold",
                  width: 2,
                  maxWidth: 2,
                },
                cellStyle: { width: 2, maxWidth: 2 },
              },
              {
                field: "downtimeId",
                headerStyle: { fontWeight: "bold" },
                title: "System Downtime ID",
              },

              {
                field: "startDateTime",
                title: "Start Date/ Time",
                headerStyle: { fontWeight: "bold" },
              },
              {
                field: "endDateTime",
                title: "End Date/ Time",
                headerStyle: { fontWeight: "bold" },
              },
              {
                field: "message",
                headerStyle: { fontWeight: "bold" },
                title: "Error Message",
              },
              {
                // field: "action",
                title: "Action",
                headerStyle: { fontWeight: "bold" },

                type: "text",
                render: (rowData) => (
                  <>
                    {" "}
                    <Link style={{ cursor: "pointer" }}>
                      {" "}
                      <EditIcon color="primary" fontSize="small" />{" "}
                    </Link>
                    <Link style={{ cursor: "pointer" }}>
                      {" "}
                      <DeleteIcon color="primary" fontSize="small" />{" "}
                    </Link>
                  </>
                ),
              },
            ]}
            options={{ exportButton: true, paginationType: "stepped" }}
            data={rows}
          ></MaterialTable>`

It doesn't reflect on screen. columns are still the same way they are.

yes this is no more working. please tell what to do and how to do. i am worried.

abhinav2000kiit avatar Mar 13 '21 23:03 abhinav2000kiit

try to put in

: root: { maxWidth: '100%', maxHeight: '100%',

  },

this can show all fields of the material-table

mpalverca avatar Apr 03 '21 01:04 mpalverca