Flexmonster – Cannot format values in first column

I’m trying to configure the following code in order to format the PROFIT column (which is the first one) as a currency.

Right now the values in that column are getting shown as:

1243898
1538192
1921982

But I want them to get shown as:

$1,243,898
$1,538,192
$1,921,982

Here you have a preview…

enter image description here

And below is the code, where you can see I introduced a new format: currency which I tried to use for that first column: PROFIT, but had no success.

<html>
<head>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<script src="https://cdn.flexmonster.com/flexmonster.js"></script>
<script>
$(function() {
    let pivot = new Flexmonster({
        container: "pivot-container",
        componentFolder: "https://cdn.flexmonster.com/",
        toolbar: false,
        report: {
            data: [
                {
                    "Profit": "1243898",
                    "Following": 81,
                    "Followers": 242,
                },
                {
                    "Profit": "1538192",
                    "Following": 728,
                    "Followers": 2178,
                },
                {
                    "Profit": "1921982",
                    "Following": 4423,
                    "Followers": 12387,
                },
                {
                    "Profit": "1243898",
                    "Following": 63,
                    "Followers": 189,
                },
                {
                    "Profit": "1538192",
                    "Following": 342,
                    "Followers": 931,
                },
                {
                    "Profit": "1538192",
                    "Following": 487,
                    "Followers": 1242,
                },
                {
                    "Profit": "1921982",
                    "Following": 3827,
                    "Followers": 15281,
                },
                {
                    "Profit": "1243898",
                    "Following": 97,
                    "Followers": 279,
                },
                {
                    "Profit": "1538192",
                    "Following": 242,
                    "Followers": 728,
                },
                {
                    "Profit": "1921982",
                    "Following": 4921,
                    "Followers": 12489,
                },
                {
                    "Profit": "1243898",
                    "Following": 69,
                    "Followers": 182,
                },
            ],
            formats: [
                {
                    name: "",
                    thousandsSeparator: " ",
                    decimalSeparator: ".",
                    decimalPlaces: -1,
                    maxDecimalPlaces: -1,
                    maxSymbols: 20,
                    currencySymbol: "",
                    negativeCurrencyFormat: "-$1",
                    positiveCurrencyFormat: "$1",
                    isPercent: "false",
                    nullValue: "",
                    infinityValue: "Infinity",
                    divideByZeroValue: "Infinity",
                    textAlign: "right",
                    beautifyFloatingPoint: true,
                },
                {
                    name: "currency",
                    currencySymbol: "$",
                },
            ],
            slice: {
                rows: [{
                    uniqueName: "Profit",
                    format: "currency",
                }],
                columns: [{
                    uniqueName: "[Measures]",
                }],
                measures: [{
                        uniqueName: "Following",
                    },
                    {
                        uniqueName: "Followers",
                    },
                ],
            },
        },
    });
});
</script>
</head>

<body>
    <div id="pivot-container"></div>
</body>

</html>

Do you have any idea on how can I make this to work?

Here you have a JSFiddle with the code above:

https://jsfiddle.net/tlg265/eo1bkjwy/

Thanks!

multiple url path ways with prox

I’am trying to get my front end to when the 1st proxy returns a 404 response it will try two use the second proxy link and then if that fails finally produce an out put of “error bad pathway” if both fail. Below is what i have at the moment.

function Wordcount()

{

let xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {   
    
        if (this.readyState == 4 && this.status == 200) {
        var j = JSON.parse(this.response);
        document.getElementById('output').value = j.answer;
        
        
    } 
    
    else {
        document.getElementById('output').value = "error bad pathway";
    }
          
};
let url = proxyURl + "/?text=" + encodeURI(document.getElementById('content').value) + "&route=" + "wordcount";
xhttp.open("GET",url);
        xhttp.send();

}

jQuery .append doesn’t work with $(document).ready

This is a followup to toggleClass of parent div not changing with onClick

In my HTML layout, I’ve found that I need to generate the div #filters after the records, not before, because I need to use PHP to build the buttons for each state. This gave me the idea to use jQuery .append to move the #filters to the #move-filters-here above the records. But after I filter on a state, the filters appear below the records and .append doesn’t work to move the #filters to #move-filters-here above the records.

Is .append not working with (document).ready?

Is there a different way to get .append to move the #filters?

Does .append need to “fire” again after the Onclick function?

Fiddle: https://jsfiddle.net/j3semt6h/10/

$(document).ready(function(){

$("#filters").append("#move-filters-here");

$('.state-button').on('click', function() {

  let _this = $(this);

  if (!_this.hasClass('active')) {

    $('.state-button.active, .record.active').removeClass('active');
    $('[data-state=' + _this.data('state') + ']').addClass('active');

  }

});

});
  .record {
    display: none;
}

.state-button {
    border: 2px solid #c2c2c2;
    padding: 5px;
    border-radius: 5px;
    margin: 0 10px 0 10px;
}

.state-button.active {
    border-color: red;
}

.record.active {
    display: block;
}
 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

<div id="move-filters-here"></div>

<div class="record" data-state="AK">
    <h1 class="name">Customer 1</h1>
    <ul>
        <li class="focus">Focus: </li>
        <li class="course">Course: </li>
        <li class="business">Business: </li>
        <li class="address">Location: 345 Cow Town, Anchorage, <span class="state">AK</span></li>
    </ul>
</div>
<div class="record" data-state="AR">
    <h1 class="name">Customer 2</h1>
    <ul>
        <li class="focus">Focus: </li>
        <li class="course">Course: </li>
        <li class="business">Business: </li>
        <li class="address">Location: Mobile, <span class="state">AR</span></li>
    </ul>
</div>
<div class="record" data-state="CA">
    <h1 class="name">Customer 3</h1>
    <ul>
        <li class="focus">Focus: </li>
        <li class="course">Course: </li>
        <li class="business">Business: </li>
        <li class="address">Location: Los Angeles <span class="state">CA</span></li>
    </ul>
</div>

<div class="record" data-state="AZ">
    <h1 class="name">Customer 3</h1>
    <ul>
        <li class="focus">Focus: </li>
        <li class="course">Course: </li>
        <li class="business">Business: </li>
        <li class="address">Location: Flagstaff <span class="state">AZ</span></li>
    </ul>
</div>

<div class="record" data-state="UT">
    <h1 class="name">Customer 3</h1>
    <ul>
        <li class="focus">Focus: </li>
        <li class="course">Course: </li>
        <li class="business">Business: </li>
        <li class="address">Location: SLC <span class="state">UT</span></li>
    </ul>
</div>


<div id="filters">
<button class="state-button state-button-ak" data-state="AK">Alaska</button>
<button class="state-button state-button-ar" data-state="AR">Arkansas</button>
<button class="state-button state-button-ca" data-state="CA">California</button>
<button class="state-button state-button-ca" data-state="AZ">Arizona</button>
<button class="state-button state-button-ut" data-state="UT">Utah</button>
</div>

How to work with upcoming events without year

I have a React native application with events where I have event dates in ISO format. I need to work with events on a yearly repeating basis. Events include dates like birthdays and also yearly events. I need to display upcoming events for the rest of the current year then display events for the next year. How to work with events without a year and sort by current date?

events.sort((a, b) => {
    const today = new Date();
    const currentYear = today.getFullYear();
    const dateA = new Date(a.date);
    dateA.setFullYear(currentYear);
    const dateB = new Date(b.date);
    dateB.setFullYear(currentYear);
    return dateA - dateB;
})
.filter(event => {
    const today = new Date();
    const currentYear = today.getFullYear();
    const eventDate = new Date(event.date);
    eventDate.setFullYear(currentYear);
    return eventDate > today;
})
.splice(0, 5)
.map(event => {
...

How to handle states in typescript?

Hello I am new to typescript and I have job to do here.
I need to make dynamic class, something like in this code bellow.

import React, { ReactNode, useState } from "react";

interface Props {
  text: ReactNode;
}

const ListItem = ({ text }: Props) => {
    let [showMore, setShowMore] = useState(false);

    return (
        <div className="item">
            <div>
                <div className={`text ${showMore ? "active" : ""}`}>{text}</div>
            </div>
            <button onClick={() => setShowMore((s) => !s)}>Show more</button>
        </div>
    );
};

But I need to implement it to this code and I have no idea how to do it, because I don’t understand this syntax from someone who wrote it.
When I try to implement previous code, I have problem with react hooks rendering in this syntax.

I hope you understand my problem

type DeliveryBranchHitProps = {
  hit: SearchIndex.DeliveryBranch;
};
const DeliveryBranchHit = ({
  hit: delivery_branch,
}: DeliveryBranchHitProps): JSX.Element => (
  <>
      <div className={`branch-opening-week ${showMore ? "active" : ""}`}>
        <p>
          <span className="branch-day">Monday:</span>
          {delivery_branch.opening_monday}
        </p>
        <button onClick={() => setShowMore((s) => !s)}>Show more</button>

    </div>
  </>
);

Return dynamically populated object literal in javascript

A little new to JS. It seems to me something like this would be possible, but after spending a few hours of getting nowhere, I’m wondering if there actually is a way to make something like this work. It’s just a function that returns an object, but the key values are set in the function instead of being passed to it:

function makeProduct() {
      return {
          Id = '0',
          Name = document.getElementById('Name').value,
          Price = document.getElementById('Price').value,
          Category = document.getElementById('Category').value
      };
    }

It seems like this would save a lot of duplicate code, instead of having to get the user input, assign it to variables, and then populate the object with the more proper syntax:

function product(id, name, price, category) ...

I was able to accomplish what I was trying to do with a class, but it does generate a lot more code. If you had a large object, you are typing a lot of the same things multiple times.

I do have some code that works using jquery, but if I try and put it in a function that returns the object, it errors out on me, too.

The whole point of the code is to call the function, return the object, and use Axios to send it to my webAPI.

async function makeGetRequest() {

  var product = makeProduct();

let res = await axios.post('http://localhost:56730/api/product/', product);

let data = res.data;
console.log(data);
}

And it does work as expected with my class.

Also, because of the keywords in this question, this is something really hard to search for and get relevant answers.

VSCode multiple versions of custom snippets

I am creating custom javascript snippets in VS Code. I have a snippet that creates a React component class, but using the same prefix, I want to have a slightly different version of the react component class. This is my code:

   "Creates a React component class": {
        "prefix": "rcc",
        "body": [
          "import React from 'react'",
          "",
          "class ${1:className} extends React.Component {",
          "    render() {",
          "        return (",
          "            <div>",
          "",
          "            </div>",
          "        )",
          "    }",
          "}",
          "",
          "export default ${1:className}"
        ],
        "description": "Creates a React component class"
    },

I want to type rcc and have it give me two options, one is default, and the other pastes this code:

   "Creates a React component class": {
        "prefix": "rcc",
        "body": [
          "import React from 'react'",
          "",
          "class ${1:className} extends React.Component {",    
          "    render() {",
          "        const runCallback = (cb) => {",
          "            return cb()",
          "         }",
          "        return (",
          "            <div>",
          "",
          "            </div>",
          "        )",
          "    }",
          "}",
          "",
          "export default ${1:className}"
        ],
        "description": "Creates a React component class"
    },

JS d3 obtained element width is less than the hardcoded value

CSS:

#full_bar {
  width: 240px;
}

JS:

console.log(d3.select('#full_bar').style('width'));

Output is ‘208px’.
If I change the hardcoded value of ‘240’ to a different one, the output is always a fixed percentage of the hardcoded value. I assume the CSS style is being overwritten, but I don’t know where. If I inspect it in the browser it says the width is 240px, and the visual bar doesn’t appear to be cropped at all.
Any advice?

Discord.js Interaction await messages cannot get message objects

Once a user creates an interaction in a discord channel I want to listen for new incomming messages in that channel. Here is the code I got

if(interaction.customId.startsWith("TRIGGER")){
let filter = m => m.author.id === interaction.author.id
interaction.channel.send(`Are you sure to delete all data? `YES` / `NO``).then(() => {
  interaction.channel.awaitMessages(filter, {
      max: 1,
      time: 30000,
      errors: ['time']
    })
    .then(message => {
      message = message.first()
      if (message.content.toUpperCase() == 'YES' || message.content.toUpperCase() == 'Y') {
        message.channel.send(`Deleted`)
      } else if (message.content.toUpperCase() == 'NO' || message.content.toUpperCase() == 'N') {
        message.channel.send(`Terminated`)
      } else {
        message.channel.send(`Terminated: Invalid Response`)
      }
    })
    .catch(collected => {
        interaction.channel.send('Timeout');
    });
})

However I dont get the message objects. Its like no messages are send

How can I solve this issue ?

What is the best way to account for some events in an input feild?

Nested if statements for checking whether the fields are empty or complying with other parameters

   if (Name != '' && age != '') {
    if(age >= 18)
    alert("Successfully Submitted!"); 

    else
    alert("you must be over 18 :(");
    }

    else
    alert("cant be empty :(");

how do i check for individual fields with multiple parameters and respond accordingly for each event without having to nest a million if statements?