Code Monkey home page Code Monkey logo

Comments (15)

haniamine avatar haniamine commented on June 11, 2024 8

I tried a lot of things but currently the only one that worked for me is using a "render" instead of
"dataIndex" at the columns.
render: (record) => record.object.attribute

so i'm suggesting this:

const data = [{
  name: "John", 
  age: 25 , 
  custom: {
    one: 1, 
    two: 2
  }
}]

const columns = [{
  title: "Name",
  dataIndex: "name"
}, {
  title: "Age",
  dataIndex: "age"
}, {
  title: "My custom property one",
 render: (record) => record.custom.one
}, {
  title: "My custom property two",
render: (record) => record.custom.two
}]

from table.

khanakia avatar khanakia commented on June 11, 2024 7

You are doing wrong. Do this way

const columns = [
  {
    title: 'image',
    dataIndex: ['notificationImage', 'url'],  // This is what changed
    key: 'notificationImage.url',
    render: (record) =>
    //console.log(text, record && record.notificationImage && record.notificationImage.url, index)
    {
      record && record.notificationImage &&
        <img
          width="460" height="345"
          src={record.notificationImage.url} />
    }
  },]

from table.

haniamine avatar haniamine commented on June 11, 2024 5

@khanakia For sorting it's the same thing, you need to add sorter to columns:

{
    title: "My custom property one",
    sorter: (a, b) => a.custom.one-b.custom.one,
    render: (record) => record.custom.one,
  }

if your column had string values:

sorter: (a, b) => a.custom.one.localeCompare(b.custom.one),

from table.

benjycui avatar benjycui commented on June 11, 2024

Or https://github.com/benjycui/exist.js 😅

from table.

afc163 avatar afc163 commented on June 11, 2024

We need this, PR welcome~ @queimadus

from table.

bodfaj13 avatar bodfaj13 commented on June 11, 2024

This should help
https://ant.design/components/table/#Migrate-to-v4

from table.

khanakia avatar khanakia commented on June 11, 2024

I cannot sort the tables anymore because it sends the fields like this now
sortField: ["serviceType", "title"]
but I need it to the like this
sortField: ["serviceType.title"]

So how to do that ???

from table.

khanakia avatar khanakia commented on June 11, 2024

I tried a lot of things but currently the only one that worked for me is using a "render" instead of
"dataIndex" at the columns.
render: (record) => record.object.attribute

so i'm suggesting this:

const data = [{
  name: "John", 
  age: 25 , 
  custom: {
    one: 1, 
    two: 2
  }
}]

const columns = [{
  title: "Name",
  dataIndex: "name"
}, {
  title: "Age",
  dataIndex: "age"
}, {
  title: "My custom property one",
 render: (record) => record.custom.one
}, {
  title: "My custom property two",
render: (record) => record.custom.two
}]

You are giving the solution to render the value. But I was talking about sortField when you click on the Sorting Icon in Table Header then it sends the value like that as I said above.

from table.

khanakia avatar khanakia commented on June 11, 2024

Ah, i see. I will give it a try. :) Thanks

from table.

rikinshah23 avatar rikinshah23 commented on June 11, 2024

How to approach when trying to render an image?
I am trying below but its not showing image.

const columns = [
  {
    title: 'image',
    dataIndex: 'notificationImage.url',
    key: 'notificationImage.url',
    render: (record) =>
    //console.log(text, record && record.notificationImage && record.notificationImage.url, index)
    {
      record && record.notificationImage &&
        <img
          width="460" height="345"
          src={record.notificationImage.url} />
    }
  },]

from table.

rikinshah23 avatar rikinshah23 commented on June 11, 2024

@khanakia Thanks. That worked!

from table.

rajkumarWebelight avatar rajkumarWebelight commented on June 11, 2024

What when you search data {firstName+lastName} in Table column

from table.

fridolinf avatar fridolinf commented on June 11, 2024

sorry may i ask. how to display it if the row name is the same, if i match it it will output like this
image
image

so I want get the name of product
image

but user hame same name
image

I want get the value name of product and user
image

from table.

khanakia avatar khanakia commented on June 11, 2024

@fridolinf it seems record.product is NULL please double check the DATA you are passing to the table.

from table.

fridolinf avatar fridolinf commented on June 11, 2024

@fridolinf it seems record.product is NULL please double check the DATA you are passing to the table.

thank you for answering my question. I solved the problem
image

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.