Array.toSorted() thinks 6 is higher than 49
Please know, the pic of data doesn't match up w/ title
But anyway, so I'm trying to get it to sort the groups in various ways (Currently testing phase so it's all just in the console)
Anyway, so when it comes down to the things like projects, tasks, bugs
It would for example sort it (with this javascript code) like this [ 13, 15, 21, 49, 6, 6]
What is the cause for this?
Also, on a sidenote, if anyone knows of a way that I can shorten it, please do tell
I tried to just have "let appendix" or whatever in the switch case, and make that innerHTML, value, etc but that never seemed to work wel ldue to it becoming a string


53 Replies
where can we see a live example of the code?
well, the code is on a localhost...
I can't exactly throw a localhost here
bc it also has php code
which is directly linked into the page
we just need the front-end code
sure, give me a sec
you can go to the element inspector and copy the inner html
and then put the js and css and html into codepen or jsfiddle
but please, reduce it as much as possible, but leave enough for us to see the problem
i can see that you're sorting strings, but the code is too hard to follow
i didnt read what you said yet sorry!
so, your sorting issues are simple
you are sorting strings
javascript reads character by character, when sorting strings
'7' > '42'
is true, but '37' > '42'
is falseso I should basically parse them as int
and it should be fine
no
oh
god no
ew
:(
🤣
reading html is the worst way to do this type of stuff
I'll slap you for that
Anyway, what would the solution be then
yes I know, but I don't have a database attached yet
and as its set up now
ive just created random numbers
everytime
what you can do instead is to have all the in an object
for example, you have an object with the title, creator, number of tasks and blah blah blah and the element
I mean, I do have a
and so on
but
maybe an id too
to add that manually to then replace
yes, that, into js
you can use json for that
but without the email and pass
I haven't worked with json before
yeh that's fair
theyre just example accounts as im testing things out first
just groups with the name of the creator
so hold on, should I create the json files as if they would be the databases?
no
you're not creating a json file
you're throwing the json into javascript with
json_encode
but how do I get the json then? xd
you create a new array with this
with the exact structure of what you want to pass to javascript
so, just so I understand correctly what you're saying
I should create an array such as what I send in that message (but w/o the pass&mail)
then when that's been made, I do array.json_encode ?
I 've never worked w/ json before so yh
well, I have read data from it long ago but that's different
basically, in php, you build the data that you need for the front-end
oh, I can convert a php array into json
right yeh I looked it up while waiting xd
so I write the array in php, then I do array.json_encode() n then the json is there
then from there I use the data inside of the json file
isntead of the html page, which was merely for testing
something like this
but you send what you would use to create each box
aight, thankyou
oh, im not finished
that's just step 1
alright, im here!
step 2: render normally the cards
step 3: use javascript to sort the data
step 4: remove all the elements and re-add the elements again
more steps or?
that's literally it
remember that you're sorting the array with the data, and not the elements
by removing the elements and adding them all again, you've sorted everything in html as well
I see, makes sense, thanks
you're welcome
oh, wait, i forgot one step
yh?
after step 2, you have to read the parent element that has the cards, and store the element into the array with the data
and on step 2, you have to have a
data-id
on each card, with the id of each groupalright
I think I understand
try implementing it then
aight
good luck
at the add slashes, I assume you mean the path to the php file?
no, i mean exactly what i did in the example
what
so its literally just "addslashes(json_encode)" just like that?
oh didnt know it was an actual thing
echo '<script> const data = JSON.parse("', addslashes(json_encode($data)), '")</script>';
^ this is what i wrote
it adds slashes to specific characters, which is a pretty common escape characteralright, got it
hold on, quick question
the tasks & bugs would be the cumsum of tasks&bugs from all the projects in projects[] (as every group can have multiple projects)
but would it be wise to nest that many layers down or should I create a seperate JSON to hold the projects
and in the groups just put PROJECT[ id => 2, id =>4] etc
or how should I handle that one
oh wait
nvm
is this nested too deeply or doesn't that really matter? @ἔρως

oh it actually looks clean enough in the console bc of the json structure
what you pass to javascript is what you use to render the cards
the exact same stuff