Update a table populated with JSON data with a button click?

156
February 11, 2018, at 05:26 AM

So I have a table of definitions that I want to be able to filter by category of the word. So when a user pressed a button it will sort by whichever category they pressed. How would I go about doing this, as I can only find examples that use forms, but mine isn't a form. I believe I will need to have a get request on the button that requests all the data with a certain category, however, I don't know how to do this.

The JSON data

{
  "definitions":[
    {
      "Category":"Algorithms",
      "Word":"Algorithm",
      "Meaning":"A process or set of rules to be followed in calculations or other problem-solving operations, especially by a computer."
    },{
      "Category":"Algorithms",
      "Word":"Binary Search",
      "Meaning":"Search a sorted array by repeatedly dividing the search interval in half. "
    },{
      "Category":"Algorithms",
      "Word":"Linear Search",
      "Meaning":"Linear search, also known as sequential search, is a process that checks every element in the list sequentially until the desired element is found."
    },{
      "Category":"Exchanging Data",
      "Word":"HTML",
      "Meaning":"Hypertext Markup Language, a standardized system for tagging text files to achieve font, colour, graphic, and hyperlink effects on World Wide Web pages."
    },{
      "Category":"Exchanging Data",
      "Word":"TCP IP",
      "Meaning":"A set of network protocol layers that work together"
    },{
      "Category":"Software Development",
      "Word":"Agile software development",
      "Meaning":"Agile software development is a group of software development methods in which requirements and solutions evolve through collaboration between self-organizing, cross-functional teams."
    }
  ]
}

How I am currently sending the data

app.get('/definitions', function (req, res) {
  var contents = fs.readFileSync("defs.json");
  var jsonContent = JSON.parse(contents);
  res.render('definitions', {title: "Title", defs: jsonContent.definitions})
})

And here's how I am populating the table using PUG (Formerly Jade)

.container.defs-body
  table.table.defs-table.table-hover
    thead.thead
      tr
        th Category
        th Word
        th Meaning
    tbody.defs-table-body
      each definition in defs
        tr
          td= definition.Category
          td= definition.Word
          td= definition.Meaning

Thanks.

READ ALSO
node.js convert emojis into unicode or something else?

node.js convert emojis into unicode or something else?

I am trying to mess around with the facebook-chat-api NPM packageI am trying to check whenever the message

199
Use Node.JS as secondary server to PHP

Use Node.JS as secondary server to PHP

I am using and developing a website on an Apache2 Server with PHP 7Because I'd like to use Firebase Auth and want to be able to manage the Auth-Accounts within my Webapp I need the Firebase Admin SDK

163
How to pass a resolved promise value to another function?

How to pass a resolved promise value to another function?

How do I pass the the returned Promise value to another function? I need to retrieve a parsed JSON data and then use that response data to send to Slack channel

158