The Add New Row demo of the jQuery Grid.
A live JavaScript/jQuery example of jqxGrid, the jQWidgets Grid component, with its complete source code below. It is one of 139 jqxGrid demos for jQuery.
everpresentrowposition property – Sets the position of the ever present row.showeverpresentrow property – Shows or hides an additional row in jqxGrid which allows you to easily add new rows.selectionmode property – Sets or gets the selection mode.width property – Sets or gets the Grid's width.columns property – Sets the Grid columns.editable property – The editable property enables or disables the Grid editing feature.filterable property – Enables or disables the Grid Filtering feature.source property – Sets and gets the source.To run it in your own page, load jqx.base.css, a theme and the library files below from npm (npm install jqwidgets-scripts) or the jsDelivr CDN, then add the markup and the script. jQuery is not required: jqxcore.js provides $. Getting started with jqxGrid shows the setup step by step.
The page loads jqx.base.css, a theme and these library files: jqxcore.js, jqxdata.js, jqxbuttons.js, jqxscrollbar.js, jqxlistbox.js, jqxdropdownlist.js, jqxmenu.js, jqxgrid.js, jqxgrid.filter.js, jqxgrid.sort.js, jqxgrid.selection.js, jqxgrid.edit.js, jqxgrid.columnsresize.js, jqxpanel.js, jqxcalendar.js, jqxradiobutton.js, jqxdatetimeinput.js, jqxcheckbox.js.
It also loads helper scripts of this demo site, which are not part of the library: demos.js (getWidth() and other layout helpers), generatedata.js (generatedata(), random sample rows).
$(document).ready(function () {
var data = generatedata(10);
var source =
{
localdata: data,
datafields:
[
{ name: 'name', type: 'string' },
{ name: 'productname', type: 'string' },
{ name: 'available', type: 'bool' },
{ name: 'date', type: 'date'},
{ name: 'quantity', type: 'number' }
],
datatype: "array"
};
var dataAdapter = new $.jqx.dataAdapter(source);
$("#grid").jqxGrid(
{
width: getWidth('Grid'),
filterable: true,
source: dataAdapter,
showeverpresentrow: true,
everpresentrowposition: "top",
editable: true,
selectionmode: 'multiplecellsadvanced',
columns: [
{
text: 'Name', columntype: 'textbox', filtertype: 'input', datafield: 'name', width: 215
},
{
text: 'Product', filtertype: 'checkedlist', datafield: 'productname', width: 220
},
{ text: 'Ship Date', datafield: 'date', filtertype: 'range', width: 210, cellsalign: 'right', cellsformat: 'd' },
{ text: 'Qty.', datafield: 'quantity', filtertype: 'number', cellsalign: 'right' }
]
});
$("#top").jqxRadioButton({ checked: true });
$("#bottom").jqxRadioButton();
$("#top").on('checked', function () {
$("#grid").jqxGrid('everpresentrowactions', 'add reset');
});
$("#bottom").on('checked', function () {
$("#grid").jqxGrid('everpresentrowactions', 'addBottom reset');
});
});
<div id="grid">
</div><br>
<div id="top">Add New Row to Top</div>
<div id="bottom">Add New Row to Bottom</div>