How can i sort the table by “DateAdded” in Material UI Table Component for React Js?How do you sort a dictionary by value?How do I sort a list of dictionaries by a value of the dictionary?How do I sort a dictionary by value?How do I sort an NSMutableArray with custom objects in it?How to sort an array of integers correctlyHow to sort a dataframe by multiple column(s)How to Sort Multi-dimensional Array by Value?How to Sort a List<T> by a property in the objectHow can I sort a dictionary by key?Can you force a React component to rerender without calling setState?

Cleaning Edwardian tiles found under more recent tiles

Subtle ways to render a planet uninhabitable

Deflecting lasers with lightsabers

Password management for kids - what's a good way to start?

(7 of 11: Fillomino) What is Pyramid Cult's Favorite Shape?

Basic CPA walkthrough

Is this popular optical illusion made of a grey-scale image with coloured lines?

Is there any difference between "result in" and "end up with"?

Subverting the essence of fictional and/or religious entities; is it acceptable?

What does Argus Filch specifically do?

Accurately recalling the key - can everyone do it?

In MTG, was there ever a five-color deck that worked well?

How to call made-up data?

Phase portrait of a system of differential equations

Astable 555 circuit not oscillating

What is a summary of basic Jewish metaphysics or theology?

Is the "muddled thoughts" from Synaptic Static a magical effect?

Meaning of ギャップ in the following sentence

What printing process is this?

Is an "are" omitted in this sentence

What is Modern Vipassana?

Confused over role of 「自分が」in this particular passage

What does "autolyco-sentimental" mean?

How to understand "...to hide the evidence of mishandled magic, or else hidden by castle-proud house-elves" in this sentence



How can i sort the table by “DateAdded” in Material UI Table Component for React Js?


How do you sort a dictionary by value?How do I sort a list of dictionaries by a value of the dictionary?How do I sort a dictionary by value?How do I sort an NSMutableArray with custom objects in it?How to sort an array of integers correctlyHow to sort a dataframe by multiple column(s)How to Sort Multi-dimensional Array by Value?How to Sort a List<T> by a property in the objectHow can I sort a dictionary by key?Can you force a React component to rerender without calling setState?






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








0















I am using Table Component of Material UI in my React Project. I have multiple columns in that which includes the record added on that date. How can I sort my table based on the date when the record is added?
I am receiving UNIX Timestamp and converting it in mm/dd/yyyy format for readability.



I am using Materila -ui Table component :
https://material-ui.com/demos/tables/



I tried to pass an array of Dates to sort function but it did not work out as it is expecting the array with all the columns.



The expected behavior is that when I click on sort icon nearby date added column, it should sort the table based on date added either Ascending or Descending.



function desc(a, b, orderBy) 
console.log(a.addedDate)
if (b.addedDate < a.addedDate)
console.log(b.addedDate)
return -1;

if (b.addedDate > a.addedDate)
return 1;

return 0;


function stableSort(array, cmp)
const stabilizedThis = array.map((el, index) => [el, index]);
stabilizedThis.sort((a, b) =>
const order = cmp(a[0], b[0]);
if (order !== 0) return order;
return a[1] - b[1];
);
return stabilizedThis.map(el => el[0]);


function getSorting(order, orderBy)
return order === 'desc' ? (a, b) => desc(a, b, orderBy) : (a, b) =>
-desc(a, b, orderBy);


const rows = [
id: 'id', numeric: false, label: 'ID',
id: 'lastname', numeric: true, label: 'lastname' ,
id: 'firstname', numeric: true, label:'firstname' ,
id: 'email', numeric: true, label: 'email',
id: 'dateadded', numeric: true, label: 'dateadded'
];


class EnhancedTableHead extends React.Component
createSortHandler = property => event =>
this.props.onRequestSort(event, property);
;

render()
const onSelectAllClick, order, orderBy, numSelected, rowCount
= this.props;

return (
<TableHead>
<TableRow>
<TableCell padding="checkbox">
<Checkbox
indeterminate=numSelected > 0 && numSelected < rowCount
checked=numSelected === rowCount
onChange=onSelectAllClick
/>
</TableCell>
rows.map(
row => (
<TableCell
key=row.id
align=row.numeric ? 'right' : 'left'
padding=row.disablePadding ? 'none' : 'default'
sortDirection=orderBy === row.id ? order : false
>
<Tooltip
title="Sort"
placement=row.numeric ? 'bottom-end' : 'bottom-start'
enterDelay=300
>
<TableSortLabel
active=orderBy === row.id
direction=order
onClick=this.createSortHandler(row.id)
>
row.label
</TableSortLabel>
</Tooltip>
</TableCell>
),
this,
)
</TableRow>
</TableHead>
);



My Table Body looks like following:

<TableBody>
stableSort(data, getSorting(order, orderBy).slice(page* rowsPerPage, page * rowsPerPage + rowsPerPage)
.map(n =>
var convertedTimeStamp;
var d = new Date(n.addedDate);
convertedTimeStamp = d.toLocaleDateString();
if (n.nuid.indexOf(this.state.filterText) === -1 )
return;

return (
<TableRow
hover

tabIndex=-1
key=n.id
>
<TableCell padding="checkbox">
</TableCell>
<TableCell component="th" scope="row" padding="none">
n.id
</TableCell>
<TableCell align="left">n.lastName</TableCell>
<TableCell align="left">n.firstName</TableCell>
<TableCell align="left">n.email</TableCell>
<TableCell align="right">convertedTimeStamp .
</TableCell>

</TableRow>
);
)

</TableBody>









share|improve this question


























  • Can you share the code for sort function? It is very difficult to help without having any code for reference.

    – User97
    Mar 27 at 5:50











  • Have updated my question @User97

    – Purvish Oza
    Mar 27 at 16:55











  • did you manage to solve the problem? I`m having hte same issue now

    – Masha
    Jul 4 at 15:07











  • Yes. I have updated my desc function, where 'a' is an object of an array representing the whole table data. Please take a look. @Masha

    – Purvish Oza
    Jul 11 at 4:29


















0















I am using Table Component of Material UI in my React Project. I have multiple columns in that which includes the record added on that date. How can I sort my table based on the date when the record is added?
I am receiving UNIX Timestamp and converting it in mm/dd/yyyy format for readability.



I am using Materila -ui Table component :
https://material-ui.com/demos/tables/



I tried to pass an array of Dates to sort function but it did not work out as it is expecting the array with all the columns.



The expected behavior is that when I click on sort icon nearby date added column, it should sort the table based on date added either Ascending or Descending.



function desc(a, b, orderBy) 
console.log(a.addedDate)
if (b.addedDate < a.addedDate)
console.log(b.addedDate)
return -1;

if (b.addedDate > a.addedDate)
return 1;

return 0;


function stableSort(array, cmp)
const stabilizedThis = array.map((el, index) => [el, index]);
stabilizedThis.sort((a, b) =>
const order = cmp(a[0], b[0]);
if (order !== 0) return order;
return a[1] - b[1];
);
return stabilizedThis.map(el => el[0]);


function getSorting(order, orderBy)
return order === 'desc' ? (a, b) => desc(a, b, orderBy) : (a, b) =>
-desc(a, b, orderBy);


const rows = [
id: 'id', numeric: false, label: 'ID',
id: 'lastname', numeric: true, label: 'lastname' ,
id: 'firstname', numeric: true, label:'firstname' ,
id: 'email', numeric: true, label: 'email',
id: 'dateadded', numeric: true, label: 'dateadded'
];


class EnhancedTableHead extends React.Component
createSortHandler = property => event =>
this.props.onRequestSort(event, property);
;

render()
const onSelectAllClick, order, orderBy, numSelected, rowCount
= this.props;

return (
<TableHead>
<TableRow>
<TableCell padding="checkbox">
<Checkbox
indeterminate=numSelected > 0 && numSelected < rowCount
checked=numSelected === rowCount
onChange=onSelectAllClick
/>
</TableCell>
rows.map(
row => (
<TableCell
key=row.id
align=row.numeric ? 'right' : 'left'
padding=row.disablePadding ? 'none' : 'default'
sortDirection=orderBy === row.id ? order : false
>
<Tooltip
title="Sort"
placement=row.numeric ? 'bottom-end' : 'bottom-start'
enterDelay=300
>
<TableSortLabel
active=orderBy === row.id
direction=order
onClick=this.createSortHandler(row.id)
>
row.label
</TableSortLabel>
</Tooltip>
</TableCell>
),
this,
)
</TableRow>
</TableHead>
);



My Table Body looks like following:

<TableBody>
stableSort(data, getSorting(order, orderBy).slice(page* rowsPerPage, page * rowsPerPage + rowsPerPage)
.map(n =>
var convertedTimeStamp;
var d = new Date(n.addedDate);
convertedTimeStamp = d.toLocaleDateString();
if (n.nuid.indexOf(this.state.filterText) === -1 )
return;

return (
<TableRow
hover

tabIndex=-1
key=n.id
>
<TableCell padding="checkbox">
</TableCell>
<TableCell component="th" scope="row" padding="none">
n.id
</TableCell>
<TableCell align="left">n.lastName</TableCell>
<TableCell align="left">n.firstName</TableCell>
<TableCell align="left">n.email</TableCell>
<TableCell align="right">convertedTimeStamp .
</TableCell>

</TableRow>
);
)

</TableBody>









share|improve this question


























  • Can you share the code for sort function? It is very difficult to help without having any code for reference.

    – User97
    Mar 27 at 5:50











  • Have updated my question @User97

    – Purvish Oza
    Mar 27 at 16:55











  • did you manage to solve the problem? I`m having hte same issue now

    – Masha
    Jul 4 at 15:07











  • Yes. I have updated my desc function, where 'a' is an object of an array representing the whole table data. Please take a look. @Masha

    – Purvish Oza
    Jul 11 at 4:29














0












0








0








I am using Table Component of Material UI in my React Project. I have multiple columns in that which includes the record added on that date. How can I sort my table based on the date when the record is added?
I am receiving UNIX Timestamp and converting it in mm/dd/yyyy format for readability.



I am using Materila -ui Table component :
https://material-ui.com/demos/tables/



I tried to pass an array of Dates to sort function but it did not work out as it is expecting the array with all the columns.



The expected behavior is that when I click on sort icon nearby date added column, it should sort the table based on date added either Ascending or Descending.



function desc(a, b, orderBy) 
console.log(a.addedDate)
if (b.addedDate < a.addedDate)
console.log(b.addedDate)
return -1;

if (b.addedDate > a.addedDate)
return 1;

return 0;


function stableSort(array, cmp)
const stabilizedThis = array.map((el, index) => [el, index]);
stabilizedThis.sort((a, b) =>
const order = cmp(a[0], b[0]);
if (order !== 0) return order;
return a[1] - b[1];
);
return stabilizedThis.map(el => el[0]);


function getSorting(order, orderBy)
return order === 'desc' ? (a, b) => desc(a, b, orderBy) : (a, b) =>
-desc(a, b, orderBy);


const rows = [
id: 'id', numeric: false, label: 'ID',
id: 'lastname', numeric: true, label: 'lastname' ,
id: 'firstname', numeric: true, label:'firstname' ,
id: 'email', numeric: true, label: 'email',
id: 'dateadded', numeric: true, label: 'dateadded'
];


class EnhancedTableHead extends React.Component
createSortHandler = property => event =>
this.props.onRequestSort(event, property);
;

render()
const onSelectAllClick, order, orderBy, numSelected, rowCount
= this.props;

return (
<TableHead>
<TableRow>
<TableCell padding="checkbox">
<Checkbox
indeterminate=numSelected > 0 && numSelected < rowCount
checked=numSelected === rowCount
onChange=onSelectAllClick
/>
</TableCell>
rows.map(
row => (
<TableCell
key=row.id
align=row.numeric ? 'right' : 'left'
padding=row.disablePadding ? 'none' : 'default'
sortDirection=orderBy === row.id ? order : false
>
<Tooltip
title="Sort"
placement=row.numeric ? 'bottom-end' : 'bottom-start'
enterDelay=300
>
<TableSortLabel
active=orderBy === row.id
direction=order
onClick=this.createSortHandler(row.id)
>
row.label
</TableSortLabel>
</Tooltip>
</TableCell>
),
this,
)
</TableRow>
</TableHead>
);



My Table Body looks like following:

<TableBody>
stableSort(data, getSorting(order, orderBy).slice(page* rowsPerPage, page * rowsPerPage + rowsPerPage)
.map(n =>
var convertedTimeStamp;
var d = new Date(n.addedDate);
convertedTimeStamp = d.toLocaleDateString();
if (n.nuid.indexOf(this.state.filterText) === -1 )
return;

return (
<TableRow
hover

tabIndex=-1
key=n.id
>
<TableCell padding="checkbox">
</TableCell>
<TableCell component="th" scope="row" padding="none">
n.id
</TableCell>
<TableCell align="left">n.lastName</TableCell>
<TableCell align="left">n.firstName</TableCell>
<TableCell align="left">n.email</TableCell>
<TableCell align="right">convertedTimeStamp .
</TableCell>

</TableRow>
);
)

</TableBody>









share|improve this question
















I am using Table Component of Material UI in my React Project. I have multiple columns in that which includes the record added on that date. How can I sort my table based on the date when the record is added?
I am receiving UNIX Timestamp and converting it in mm/dd/yyyy format for readability.



I am using Materila -ui Table component :
https://material-ui.com/demos/tables/



I tried to pass an array of Dates to sort function but it did not work out as it is expecting the array with all the columns.



The expected behavior is that when I click on sort icon nearby date added column, it should sort the table based on date added either Ascending or Descending.



function desc(a, b, orderBy) 
console.log(a.addedDate)
if (b.addedDate < a.addedDate)
console.log(b.addedDate)
return -1;

if (b.addedDate > a.addedDate)
return 1;

return 0;


function stableSort(array, cmp)
const stabilizedThis = array.map((el, index) => [el, index]);
stabilizedThis.sort((a, b) =>
const order = cmp(a[0], b[0]);
if (order !== 0) return order;
return a[1] - b[1];
);
return stabilizedThis.map(el => el[0]);


function getSorting(order, orderBy)
return order === 'desc' ? (a, b) => desc(a, b, orderBy) : (a, b) =>
-desc(a, b, orderBy);


const rows = [
id: 'id', numeric: false, label: 'ID',
id: 'lastname', numeric: true, label: 'lastname' ,
id: 'firstname', numeric: true, label:'firstname' ,
id: 'email', numeric: true, label: 'email',
id: 'dateadded', numeric: true, label: 'dateadded'
];


class EnhancedTableHead extends React.Component
createSortHandler = property => event =>
this.props.onRequestSort(event, property);
;

render()
const onSelectAllClick, order, orderBy, numSelected, rowCount
= this.props;

return (
<TableHead>
<TableRow>
<TableCell padding="checkbox">
<Checkbox
indeterminate=numSelected > 0 && numSelected < rowCount
checked=numSelected === rowCount
onChange=onSelectAllClick
/>
</TableCell>
rows.map(
row => (
<TableCell
key=row.id
align=row.numeric ? 'right' : 'left'
padding=row.disablePadding ? 'none' : 'default'
sortDirection=orderBy === row.id ? order : false
>
<Tooltip
title="Sort"
placement=row.numeric ? 'bottom-end' : 'bottom-start'
enterDelay=300
>
<TableSortLabel
active=orderBy === row.id
direction=order
onClick=this.createSortHandler(row.id)
>
row.label
</TableSortLabel>
</Tooltip>
</TableCell>
),
this,
)
</TableRow>
</TableHead>
);



My Table Body looks like following:

<TableBody>
stableSort(data, getSorting(order, orderBy).slice(page* rowsPerPage, page * rowsPerPage + rowsPerPage)
.map(n =>
var convertedTimeStamp;
var d = new Date(n.addedDate);
convertedTimeStamp = d.toLocaleDateString();
if (n.nuid.indexOf(this.state.filterText) === -1 )
return;

return (
<TableRow
hover

tabIndex=-1
key=n.id
>
<TableCell padding="checkbox">
</TableCell>
<TableCell component="th" scope="row" padding="none">
n.id
</TableCell>
<TableCell align="left">n.lastName</TableCell>
<TableCell align="left">n.firstName</TableCell>
<TableCell align="left">n.email</TableCell>
<TableCell align="right">convertedTimeStamp .
</TableCell>

</TableRow>
);
)

</TableBody>






reactjs sorting material-ui






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jul 11 at 4:27







Purvish Oza

















asked Mar 27 at 1:22









Purvish OzaPurvish Oza

108 bronze badges




108 bronze badges















  • Can you share the code for sort function? It is very difficult to help without having any code for reference.

    – User97
    Mar 27 at 5:50











  • Have updated my question @User97

    – Purvish Oza
    Mar 27 at 16:55











  • did you manage to solve the problem? I`m having hte same issue now

    – Masha
    Jul 4 at 15:07











  • Yes. I have updated my desc function, where 'a' is an object of an array representing the whole table data. Please take a look. @Masha

    – Purvish Oza
    Jul 11 at 4:29


















  • Can you share the code for sort function? It is very difficult to help without having any code for reference.

    – User97
    Mar 27 at 5:50











  • Have updated my question @User97

    – Purvish Oza
    Mar 27 at 16:55











  • did you manage to solve the problem? I`m having hte same issue now

    – Masha
    Jul 4 at 15:07











  • Yes. I have updated my desc function, where 'a' is an object of an array representing the whole table data. Please take a look. @Masha

    – Purvish Oza
    Jul 11 at 4:29

















Can you share the code for sort function? It is very difficult to help without having any code for reference.

– User97
Mar 27 at 5:50





Can you share the code for sort function? It is very difficult to help without having any code for reference.

– User97
Mar 27 at 5:50













Have updated my question @User97

– Purvish Oza
Mar 27 at 16:55





Have updated my question @User97

– Purvish Oza
Mar 27 at 16:55













did you manage to solve the problem? I`m having hte same issue now

– Masha
Jul 4 at 15:07





did you manage to solve the problem? I`m having hte same issue now

– Masha
Jul 4 at 15:07













Yes. I have updated my desc function, where 'a' is an object of an array representing the whole table data. Please take a look. @Masha

– Purvish Oza
Jul 11 at 4:29






Yes. I have updated my desc function, where 'a' is an object of an array representing the whole table data. Please take a look. @Masha

– Purvish Oza
Jul 11 at 4:29













0






active

oldest

votes










Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55368444%2fhow-can-i-sort-the-table-by-dateadded-in-material-ui-table-component-for-react%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes




Is this question similar to what you get asked at work? Learn more about asking and sharing private information with your coworkers using Stack Overflow for Teams.







Is this question similar to what you get asked at work? Learn more about asking and sharing private information with your coworkers using Stack Overflow for Teams.



















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55368444%2fhow-can-i-sort-the-table-by-dateadded-in-material-ui-table-component-for-react%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현