jQuery addClass example

Change class name on click in jQuery

by Danish Farman

HTML

<script src="https://cdnjs.cloudflare.com/ajax/libs/jsgrid/1.5.3/jsgrid.min.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/jsgrid/1.5.3/jsgrid-theme.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/jsgrid/1.5.3/jsgrid-theme.min.css">
<script src="https://cdn.jsdelivr.net/npm/[email protected]/lib/jquery.tabletojson.min.js"></script>
<div id="jsGrid"></div>
<button id="btnUpdate">Update</button>

CSS

body {
  background: #20262E;
  padding: 20px;
  font-family: Helvetica;
}

#banner-message {
  background: #fff;
  border-radius: 4px;
  padding: 20px;
  font-size: 25px;
  text-align: center;
  transition: all 0.2s;
  margin: 0 auto;
  width: 300px;
}

button {
  background: #0084ff;
  border: none;
  border-radius: 5px;
  padding: 8px 14px;
  font-size: 15px;
  color: #fff;
}

#banner-message.alt {
  background: #0084ff;
  color: #fff;
  margin-top: 40px;
  width: 200px;
}

#banner-message.alt button {
  background: #fff;
  color: #000;
}

JavaScript

var clients = [

];

var countries = [{
    Name: "",
    Id: 0
  },
  {
    Name: "United States",
    Id: 1
  },
  {
    Name: "Canada",
    Id: 2
  },
  {
    Name: "United Kingdom",
    Id: 3
  }
];

$("#jsGrid").jsGrid({
  width: "100%",
  height: "400px",

  inserting: true,
  editing: true,
  sorting: true,
  paging: true,

  data: clients,

  fields: [{
      name: "Name",
      type: "text",
      width: 150,
      validate: "required"
    },
    {
      name: "Age",
      type: "number",
      width: 50
    },
    {
      name: "Address",
      type: "text",
      width: 200
    },
    {
      name: "Country",
      type: "select",
      items: countries,
      valueField: "Id",
      textField: "Name"
    },
    {
      name: "Married",
      type: "checkbox",
      title: "Is Married",
      sorting: false
    },
    {
      type: "control"
    }
  ]
});

$("#btnUpdate").on('click', function() {
  var table = $(".jsgrid-table").tableToJSON(); // Convert the table into a javascript object
  console.log(table);
  alert(JSON.stringify(table));
});