Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQGrid, how to add a new row inside the grid, not via a modal?

Some quick searching only turns up adding a new row to a jQGrid via a modal popup with the editable fields.

Can anyone point me to a sample or show me some code that allows you to add a new empty row into the grid itself, at the top?

I have an action column at the rightmost end of the grid in which onRowSelect() I have a save button appear and I can make that button do the save and refresh the grid I think..

I can't figure out how to click on a 'Add Row' button and add an empty row inside the grid at the top.

One option that I can see is to style the current add row modal to look like a horizontal row and place it to appear like its a row at the top of the grid.

jQGrid Documentation: http://www.trirand.com/jqgridwiki/

like image 705
Moin Zaman Avatar asked Sep 06 '10 12:09

Moin Zaman


People also ask

Is it possible to add a new row to a jqgrid?

Some quick searching only turns up adding a new row to a jQGrid via a modal popup with the editable fields. Can anyone point me to a sample or show me some code that allows you to add a new empty row into the grid itself, at the top?

How to enable edit functionality on particular column in jqgrid?

You can also add editable: true property that will enable edit functionality on particular column, if you don’t want show a column in edit modal window, you need to set editable: false against that column. Now i am enabling edit functionality on userId, title and body column, the jQgrid column code will look like below,

How to create a JQ grid application in Visual Studio 2010?

In Visual Studio 2010 first create a simple ASP.Net web project named "JQgridapplication". After that add the required JS file and folder for the JQ grid. The folder and file structure will look as shown in the following figure1 marked with red. Now go to the "about.aspx".

How to delete all the posted data in jqgrid?

here you will get all your posted data in console.log (). Delete record is another common functionality in grid listing.You need to add delete call-back function into jQgrid instance and pass parameters like delete window header, send request on ENTER button clicked etc. //delete Options. save key parameter will keybind the Enter key to submit.


2 Answers

If you use datatype:'local' then you can use addRowData method to insert the row with position parameter set to 'first'. See some examples under http://www.trirand.com/jqgridwiki/doku.php?id=wiki:retrieving_data#array_data.

like image 81
Oleg Avatar answered Oct 24 '22 12:10

Oleg


This answer is courtesy of Oleg in my previous question here:

use $("#grid").addRowData(rowid,data, position, srcrowid);

Inserts a new row with id = rowid containing the data in data (an object) at the position specified (first in the table, last in the table or before or after the row specified in srcrowid). The syntax of the data object is: {name1:value1,name2: value2…} where name is the name of the column as described in the colModel and the value is the value. This method can insert multiple rows at once. In this case the data parameter should be array defined as [{name1:value1,name2: value2…}, {name1:value1,name2: value2…} ] and the first option rowid should contain the name from data object which should act as id of the row. It is not necessary that the name of the rowid in this case should be a part from colModel.

P.S. Have a look at my profile for a number of jqgrid questions and answers.

like image 43
Bob Avatar answered Oct 24 '22 11:10

Bob