Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to achieve jqgrid inline adding row in grails ?

 
Nazeer Ahammad
Ranch Hand
Posts: 43
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

I'm using jqgrid plugin(version is 1.3.8) in grails(version is 2.2.4), inline edit is working but how to achieve inline insertion?

Please see the below code
------------------------------
<head>

<jq:resources />
<jqui:resources />
<jqgrid:resources />


<script type="text/javascript">


var lastsel2;
// var colnames='${createLink(action: 'colnames',params:'columnnames')}';
//alert(colnames);
$(document).ready(function() {

<jqgrid:grid
id="contact"
url="'${createLink(action: 'listJSON')}'"
editurl="'${createLink(action: 'editJSON')}'"
colNames="'companyname', 'exp','id'"
colModel="{name:'companyname', editable: true},
{name:'exp', editable: true},
{name:'id', hidden: true}"
sortname="'companyname'"
caption="'Company List'"
height="300"
autowidth="true"
scrollOffset="0"
viewrecords="true"
showPager="true"
datatype="'json'"
beforeSelectRow= "function (id) {
if (id !== lastsel2) {
jQuery(this).restoreRow(id,true);
lastsel2 = id;
}
return true;
}"

ondblClickRow="function(id)
{
var rowData = jQuery(this).editRow(id,true);
lastsel2=id;
}"



>

<jqgrid:filterToolbar id="contact" searchOnEnter="false" />
<jqgrid:navigation id="contact" add="false" edit="true"
del="true" search="true" refresh="true"
/>


<jqgrid:resize id="contact" resizeOffset="-2" />
</jqgrid:grid>







});


</script>

</head>
<body bgcolor="#c0c0c0">

<jqgrid:wrapper id="contact" />
<input type="button" id="addrow" value="insert">
</body>
-------------------------------
controller is
------------------
class UserController {


def messageSource
//def scaffold = Precompany

def defaultAction = "index"

def editJSON = {
def result
def message = ""
def state = "FAIL"
def id

// determine our action. Grid will pass a param called "oper"
switch (params.oper) {
// Delete Request
case 'del':
result = Precompany.get(params.id)
if (result) {
result.delete()
message = "Author '${result.companyname} ${result.exp}' Deleted"
state = "OK"
}
break;
// Add Request
case 'add':
result = new Precompany(params)
break;
// Edit Request
case 'edit':
// add or edit instruction sent
result = Precompany.get(params.id)
result.properties = params
break;
}

// If we aren't deleting the object then we need to validate and save.
// Capture any validation messages to display on the client side
if (result && params.oper != "del") {
if (!result.hasErrors() && result.save(flush: true)) {
message = "Author '${result.companyname} ${result.exp}' " + (params.oper == 'add') ? "Added" : "Updated"
id = result.id
state = "OK"
} else {
message = "<ul>"
result.errors.allErrors.each {
message += "<li>${messageSource.getMessage(it)}</li>"
}
message += "</ul>"
}
}

//render [message:message, state:state, id:id] as JSON
def jsonData = [messsage: message, state: state, id: id]
render jsonData as JSON
}

def listJSON = {
def sortIndex = params.sidx ?: 'name'
def sortOrder = params.sord ?: 'asc'

def maxRows = Integer.valueOf(params.rows)
def currentPage = Integer.valueOf(params.page) ?: 1

def rowOffset = currentPage == 1 ? 0 : (currentPage - 1) * maxRows

def authors = Precompany.createCriteria().list(max: maxRows, offset: rowOffset) {

if (params.companyname)
ilike('companyname', '%' + params.companyname + '%')

if (params.exp)
ilike('exp', '%' + params.exp + '%' )


//order(new Order(params.companyname, params.exp).ignoreCase())

//order(sortIndex, sortOrder).ignoreCase()
//resultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY)
}
println "listJson"+ authors.totalCount
def totalRows = authors.totalCount
def numberOfPages = Math.ceil(totalRows / maxRows)

def jsonCells = authors?.collect {
[
cell: [it.companyname,it.exp],
id: it.id
]
}

def jsonData= [rows: jsonCells,
page: currentPage,
records: totalRows,
total: numberOfPages]

render jsonData as JSON
}
----------------
Please help me

Regards,
Nazeer.
 
Pankaja Shinde
Ranch Hand
Posts: 87
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Check this url.
http://trirand.com/blog/jqgrid/jqgrid.html
and follow section
Row Editing (new) -> Inline Navigator (new)
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic