JavaScript Grid

Invoke the ensurerowvisible method of the jqxGrid. Author: http://jqwidgets.com

by Manu Vashishtha

HTML

<script src="https://jqwidgets.com/public/jqwidgets/jqx-all.js"></script>
<link rel="stylesheet" href="https://jqwidgets.com/public/jqwidgets/styles/jqx.base.css">
<link rel="stylesheet" href="https://jqwidgets.com/public/jqwidgets/styles/jqx.energyblue.css">
<script src="https://jqwidgets.com/jquery-widgets-demo/demos/jqxgrid/generatedata.js"></script>
<script src="http://www.jqueryscript.net/demo/Search-Keyword-Highlighting-Plugin-With-jQuery-Highlite/js/jquery.highlite.js"></script>
<script src="https://www.jqueryscript.net/demo/Search-Keyword-Highlighting-Plugin-With-jQuery-Highlite/js/jquery.highlite.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.2/css/bootstrap.min.css">
<div>
<div id="cmbColumns"></div>
	<input type="text" id="searchText" />
	<input type="button" id="goSearch" value="Search">
</div>
	<div id="jqxgrid"></div>

CSS

.green {
        color: black\9;
        background-color: #b6ff00\9;
    }
    .yellow {
        color: black\9;
        background-color: yellow\9;
    }
    .red {
        color: black\9;
        background-color: #e83636\9;
    }

    .green:not(.jqx-grid-cell-hover):not(.jqx-grid-cell-selected), .jqx-widget .green:not(.jqx-grid-cell-hover):not(.jqx-grid-cell-selected) {
        color: black;
        background-color: #b6ff00;
    }
    .yellow:not(.jqx-grid-cell-hover):not(.jqx-grid-cell-selected), .jqx-widget .yellow:not(.jqx-grid-cell-hover):not(.jqx-grid-cell-selected) {
        color: black;
        background-color: yellow;
    }
    .red:not(.jqx-grid-cell-hover):not(.jqx-grid-cell-selected), .jqx-widget .red:not(.jqx-grid-cell-hover):not(.jqx-grid-cell-selected) {
        color: black;
        background-color: #e83636;
    }

JavaScript

$(document).ready(function () {
  var source = [
      "firstname",
      "lastname",
      "productname",
      "date",
      "quantity",
      "price"];
  // Create a jqxDropDownList
  $("#cmbColumns").jqxDropDownList({
      source: source,
      selectedIndex: 0,
      theme: 'energyblue'
});


	$("#goSearch").jqxButton({
		width : '150'
	});
	
	// prepare the data
	var data = new Array();
	var firstNames =
		[
		"Andrew", "Nancy", "Shelley", "Regina", "Yoshi", "Antoni", "Mayumi", "Ian", "Peter", "Lars", "Petra", "Martin", "Sven", "Elio", "Beate", "Cheryl", "Michael", "Guylene"
	];
	var lastNames =
		[
		"Fuller", "Davolio", "Burke", "Murphy", "Nagase", "Saavedra", "Ohno", "Devling", "Wilson", "Peterson", "Winkler", "Bein", "Petersen", "Rossi", "Vileid", "Saylor", "Bjorn", "Nodier"
	];
	var productNames =
		[
		"Black Tea", "Green Tea", "Caffe Espresso", "Doubleshot Espresso", "Caffe Latte", "White Chocolate Mocha", "Cramel Latte", "Caffe Americano", "Cappuccino", "Espresso Truffle", "Espresso con Panna", "Peppermint Mocha Twist"
	];
	var priceValues =
		[
		"2.25", "1.5", "3.0", "3.3", "4.5", "3.6", "3.8", "2.5", "5.0", "1.75", "3.25", "4.0"
	];
	for (var i = 0; i < 300; i++) {
		var row = {};
		var productindex = Math.floor(Math.random() * productNames.length);
		var price = parseFloat(priceValues[productindex]);
		var quantity = 1 + Math.round(Math.random() * 10);
		row["firstname"] = firstNames[Math.floor(Math.random() * firstNames.length)];
		row["lastname"] = lastNames[Math.floor(Math.random() * lastNames.length)];
		row["productname"] = productNames[productindex];
		row["price"] = price;
		row["quantity"] = quantity;
		row["total"] = price * quantity;
		data[i] = row;
	}
	var source = {
		localdata : data,
		datatype : "array",
		datafields :
		[{
				name : 'firstname',
				type : 'string'
			}, {
				name : 'lastname',
				type : 'string'
			}, {
				name : 'productname',
				type : 'string'
			}, {
				name : 'quantity',
				type : 'number'
			},...