Giter Site home page Giter Site logo

Comments (23)

mnieber avatar mnieber commented on August 18, 2024 15

Instead of render I had to use Cell. For the rest, this solution worked.

from table.

maxwell-oroark avatar maxwell-oroark commented on August 18, 2024 10

Yes - your advised solution worked well. The column def looks like this now:

const dayColumns = [{
      header : 'Compute Usage By Day',
      columns : [{
        header: 'Day',
        accessor: 'day',
        sort: 'desc',
        render: props => <span>{moment.utc(props.value).format('MMMM Do YYYY')}</span>
      }, {
        header: 'Usage In Hours',
        id: 'usageByDay',
        accessor: data => (data.computeUsageInSeconds / 3600).toFixed(2)
      },{
        header: '%',
        id: 'dayPercentage',
        accessor: (data) => (data.computeUsageInSeconds > 0 ? ((data.computeUsageInSeconds / 3600) / computeLimitInHours).toFixed(4) : 0)
      }
      ]
    }]

I was wondering about one thing. Are the span tags necessary in the render function? At first I was trying props => moment(props.value).format(YYYY MM) but this threw some sort of error that I did not investigate. Perhaps props => {moment(props.value).format(YYYY MM) } might have worked without the span tags, anyways just a random point of curiosity.

from table.

tannerlinsley avatar tannerlinsley commented on August 18, 2024 9

from table.

alebrozzo avatar alebrozzo commented on August 18, 2024 6

I have this and it works for me:

            {
                Header: "DOB",
                id: "dob",
                accessor: c => c.dob,
                maxWidth: 120,
                Cell: c => <span>{c.original.dob && moment(c.original.dob).format("MM/DD/YYYY")}</span>,
                style: { textAlign: "center" },
            },

I know for sure that dob is a date though. If you are not, perhaps you should add something like

accessor: c => moment.utc(c.dob)

from table.

alebrozzoSP avatar alebrozzoSP commented on August 18, 2024 2

Thanks @mnieber and @gary-menzel! I needed that info. I just found on the breaking changes section of the readme that render was deprecated in favor of Cell

from table.

juanbussoli avatar juanbussoli commented on August 18, 2024 2

Thanks! It's works!

from table.

PavanKumarRao avatar PavanKumarRao commented on August 18, 2024 2

moment is not defined it says

from table.

kristibyrnes avatar kristibyrnes commented on August 18, 2024 1

What would you recommend if the some of the cells in the column are populated with a null value?

from table.

tannerlinsley avatar tannerlinsley commented on August 18, 2024

from table.

maxwell-oroark avatar maxwell-oroark commented on August 18, 2024

So my columns look this:

const dayColumns = [{ header : 'Compute Usage By Day', columns : [{ header: 'Day', id: 'day-date', sortable: false, accessor: data => moment.utc(data.day).format('MMMM Do YYYY') }, { header: 'Usage In Hours', id: 'usageByDay', accessor: data => (data.computeUsageInSeconds / 3600).toFixed(2) },{ header: '%', id: 'dayPercentage', accessor: (data) => (data.computeUsageInSeconds > 0 ? ((data.computeUsageInSeconds / 3600) / computeLimitInHours).toFixed(4) : 0) } ] }]

and my data looks like:

[{"day":"2017-02-02T00:00:00.000Z","computeUsageInSeconds":31617.909999999996},{"day":"2017-02-01T00:00:00.000Z","computeUsageInSeconds":40181.17799999999},{"day":"2017-01-31T00:00:00.000Z","computeUsageInSeconds":21089.114},{"day":"2017-01-30T00:00:00.000Z","computeUsageInSeconds":44944.111},{"day":"2017-01-29T00:00:00.000Z","computeUsageInSeconds":15069.673},{"day":"2017-01-28T00:00:00.000Z","computeUsageInSeconds":0},{"day":"2017-01-27T00:00:00.000Z","computeUsageInSeconds":0},{"day":"2017-01-26T00:00:00.000Z","computeUsageInSeconds":0},{"day":"2017-01-25T00:00:00.000Z","computeUsageInSeconds":0},{"day":"2017-01-24T00:00:00.000Z","computeUsageInSeconds":0},{"day":"2017-01-23T00:00:00.000Z","computeUsageInSeconds":0},{"day":"2017-01-22T00:00:00.000Z","computeUsageInSeconds":0},{"day":"2017-01-21T00:00:00.000Z","computeUsageInSeconds":0},{"day":"2017-01-20T00:00:00.000Z","computeUsageInSeconds":0},{"day":"2017-01-19T00:00:00.000Z","computeUsageInSeconds":0},{"day":"2017-01-18T00:00:00.000Z","computeUsageInSeconds":0},{"day":"2017-01-17T00:00:00.000Z","computeUsageInSeconds":0},{"day":"2017-01-16T00:00:00.000Z","computeUsageInSeconds":0},{"day":"2017-01-15T00:00:00.000Z","computeUsageInSeconds":0},{"day":"2017-01-14T00:00:00.000Z","computeUsageInSeconds":0},{"day":"2017-01-13T00:00:00.000Z","computeUsageInSeconds":0},{"day":"2017-01-12T00:00:00.000Z","computeUsageInSeconds":94972.638},{"day":"2017-01-11T00:00:00.000Z","computeUsageInSeconds":114119.36099999999}],[],[],[{"day":"2017-02-01T00:00:00.000Z","computeUsageInSeconds":5132.079000000001},{"day":"2017-01-31T00:00:00.000Z","computeUsageInSeconds":3491.0939999999996}]

from table.

maxwell-oroark avatar maxwell-oroark commented on August 18, 2024

Ah, gotcha. Thanks for the lightning fast reply! will give it a shot

from table.

tannerlinsley avatar tannerlinsley commented on August 18, 2024

from table.

tannerlinsley avatar tannerlinsley commented on August 18, 2024

Any update on this?

from table.

tannerlinsley avatar tannerlinsley commented on August 18, 2024

Great! I believe the span tags are. This could just be a react thing too. I'm not sure.

from table.

gary-menzel avatar gary-menzel commented on August 18, 2024

@mnieber yeah - looks like "render" was an old way of doing it (nothing in the docs now other than "Cell")

from table.

juanbussoli avatar juanbussoli commented on August 18, 2024

Hello!! I'm trying to do the same, but it does not work for me. Could you help me?

from table.

alebrozzo avatar alebrozzo commented on August 18, 2024

@juanbussoli you'd have to at least paste some of the code in order for anybody to be able to help you. I personally don't even remember this issue but I see I said myself that my issue got fixed :D

from table.

juanbussoli avatar juanbussoli commented on August 18, 2024

I have a column like this:
{
Header: "Date created",
id: "date_created",
accessor: d => d.dateCreated,
Cell: row => {row.value}
},

I need to be able to sort this column by date, however, by clicking on the title of the column, it is sorted alphabetically. Could you help me?

from table.

juanbussoli avatar juanbussoli commented on August 18, 2024

Ok, but what is "moment"?
He does not recognize me, and he tells me that it is not defined.

from table.

alebrozzo avatar alebrozzo commented on August 18, 2024

it's a date handling library. I think you could use new Date(c.dob) for testing purposes.
From here on I suggest you take it to stack overflow as this thread is becoming too verbose

from table.

PavanKumarRao avatar PavanKumarRao commented on August 18, 2024

what is moment?

from table.

flymans avatar flymans commented on August 18, 2024

what is moment?

It's a javascript library. Google moment.js

from table.

bsell93 avatar bsell93 commented on August 18, 2024

@kristibyrnes I found if you default to min date that seems to work
const MINIMUM_DATE = new Date(-8640000000000000);
accessor: ({ nullableDate }) => nullableDate ?? MINIMUM_DATE

from table.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.