Jquery jqgrid不显示数据行
当我尝试加载jqgrid时,它会显示标题,但不会添加任何包含数据的行。 这里的图片链接--> 控制器Jquery jqgrid不显示数据行,jquery,json,jqgrid,Jquery,Json,Jqgrid,当我尝试加载jqgrid时,它会显示标题,但不会添加任何包含数据的行。 这里的图片链接--> 控制器 package mobilesuits import grails.converters.JSON import static org.springframework.http.HttpStatus.* import grails.transaction.Transactional @Transactional(readOnly = true) class MobileSuitsContr
package mobilesuits
import grails.converters.JSON
import static org.springframework.http.HttpStatus.*
import grails.transaction.Transactional
@Transactional(readOnly = true)
class MobileSuitsController {
def scaffold = MobileSuits
/**
* This function renders the json for the listGrid displayed on the home page
* "listAllComicBook" corresponds to the url supplied in jqgrid
* The first 5 lines are boiler plate found on all(i think) DCmd jqgrids
* The create criteria creates a corresponding sql table of the comic book attributes
* The if statements inside the create criteria allow for searching in at the top of each column
* The ' ' in the collection corresponds to the editing action for a row on the grid -- the little pin widget
*
*/
def listAllMobileSuits = {
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 mobilesuits = MobileSuits.createCriteria().list(max: maxRows, offset: rowOffset){
if (params.name) ilike('name', "%${params.name}%")
if (params.model) ilike('model', "%${params.model}%")
if (params.affiliation) ilike('affiliation', "%${params.affiliation}%")
if (params.pilot) ilike('pilot', "%${params.pilot}%")
}
def totalRows = mobilesuits.totalCount
def numberOfPages = Math.ceil(totalRows / maxRows)
//the first attribute in the collection is for the edit feature action thing
def results = mobilesuits?.collect{[cell: ['', it.name, it.model, it.affiliation, it.pilot], id: it.id]}
def jsonData = [rows: results, page: currentPage, records: totalRows, total: numberOfPages]
render jsonData as JSON
}
/**
* This function allows for the editing of a row in the jqgrid
* "editAllComicBook" corresponds to the edit URL in the jqgrid
* Whether the attribute is editable or not depends on how you initialize the editable field for the attribute in ColModel in jqgrid
*/
def editAllMobileSuits = {
def item = null
def message = ""
def state = "FAIL"
def id
params.theObject = MobileSuits.get(params.id)
if(params.name)
params.theObject.name = params.name
if(params.model)
params.theObject.model = params.model
if(params.affiliation)
params.theObject.affiliaiton = params.affiliation
if(params.pilot)
params.theObject.pilot = params.pilot
if (! params.theObject.hasErrors() && params.theObject.save()) {
id = params.theObject.id
state = "OK"
}
def response = [state:state,id:id]
render response as JSON
}
}
查看
<script type="text/javascript">
$(document).ready(function() {//code goes here
jQuery("#allMobileSuits").jqGrid({
heigth: 'auto',
width: 'auto',
caption: 'Mobile Suits List',
url: 'MobileSuits/mobileSuits',
editurl: 'MobileSuits/editAllMobileSuits',
datatype: "json",
colNames: ['Name', 'Model', 'Affiliation', 'Pilot'],
colModel: [
//the actions column corresponds to the editurl
/* {name:'actions', index:'actions', editable:false, required:false, sortable:false, search:false, width:40, fixed: true, frozen: true,
formatter: 'actions', hidden:false, formatoptions: {
afterSave: function(e) {
$("#allMobileSuits").trigger("reloadGrid");
setTimeout(function () {
$('#allMobileSuits').jqGrid('resetSelection');
$('#allMobileSuits').jqGrid('setSelection', e);
}, 200
);
}
}},*/
{name:'name', width:200, editable:true},
{name:'model', width:200, editable:true},
{name:'affiliation', width:200, editable:true},
{name:'pilot', width:200, editable:true}
],
rowNum:20,
rowList:[20,40,60],
gridview: true,
viewrecords: true,
sortorder: "asc",
autowidth:true,
// scroll: true,
forceFit:true,
shrinkToFit: true,
pager: '#mobileSuitsAllPager',
scrollOffset:0,
gridComplete: function() {
}
});
jQuery("#allMobileSuits").jqGrid('navGrid','#mobileSuitsAllPager',{edit:false,add:false,del:false});
%{-- function to allow for searching a column for some string--}%
jQuery('#allMobileSuits').filterToolbar({id:'allMobileSuits', searchOnEnter:true});
$("#allMobileSuits").jqGrid('navGrid','#mobileSuitsAllPager',{
add:false,
del:false,
edit:false,
refresh:false,
refreshstate:"current",
search:false
},
{},//edit options
{recreateForm:true //since clearAfterAdd is trueby default, recreate the form so we re-establish value for parent id
});
%{--Not sure what exactly this does--}%
jQuery("#grid_id").jqGrid({
pager : '#allMobileSuitsPager',
});
%{--Not sure what exactly this does--}%
jQuery("#grid_id").navGrid('#allMobileSuitsPager',"add_allMobileSuits" );
jQuery(window).bind('resize', function() {
}).trigger('resize');
});
</script>
%{--tag for grid--}%
<table id="allMobileSuits"></table>
%{--tag for pager--}%
<div id="mobileSuitsAllPager"></div>
$(document).ready(function(){//代码如下
jQuery(“所有移动套件”).jqGrid({
高度:'自动',
宽度:“自动”,
描述:“手机套装列表”,
url:“手机套件/手机套件”,
editurl:'MobileSuits/editAllMobileSuits',
数据类型:“json”,
colNames:['Name','Model','Affiliation','Pilot'],
colModel:[
//actions列对应于editurl
/*{名称:'actions',索引:'actions',可编辑:false,必需:false,可排序:false,搜索:false,宽度:40,固定:true,冻结:true,
格式化程序:“操作”,隐藏:false,格式化选项:{
余波:函数(e){
$(“#所有移动套件”).trigger(“重新加载网格”);
setTimeout(函数(){
$('#allMobileSuits').jqGrid('resetSelection');
$('#allMobileSuits').jqGrid('setSelection',e);
}, 200
);
}
}},*/
{name:'name',宽度:200,可编辑:true},
{名称:'model',宽度:200,可编辑:true},
{名称:'affiliation',宽度:200,可编辑:true},
{名称:'pilot',宽度:200,可编辑:true}
],
rowNum:20,
行列表:[20,40,60],
gridview:没错,
viewrecords:是的,
分拣员:“asc”,
自动宽度:正确,
//卷轴:没错,
forceFit:对,
shrinkToFit:是的,
寻呼机:“#手机套件寻呼机”,
滚动偏移量:0,
gridComplete:函数(){
}
});
jQuery(#allMobileSuits”).jqGrid('navGrid','#mobileSuitsAllPager',{edit:false,add:false,del:false});
%{--函数,用于在列中搜索某些字符串--}%
jQuery('#allMobileSuits').filterToolbar({id:'allMobileSuits',searchOneNoter:true});
$(“#所有手机套件”).jqGrid('navGrid','#mobileSuitsAllPager'{
加:错,,
戴尔:错,
编辑:false,
刷新:false,
刷新状态:“当前”,
搜索:false
},
{},//编辑选项
{recreateForm:true//clearAfterAdd默认为true,因此重新创建表单,以便为父id重新建立值
});
%{--不确定这到底是做什么的--}%
jQuery(“网格id”).jqGrid({
寻呼机:“#所有手机套件”,
});
%{--不确定这到底是做什么的--}%
jQuery(“#grid#u id”).navGrid(“#allMobileSuitsPager”,“add#allMobileSuits”);
jQuery(window).bind('resize',function()){
}).trigger('resize');
});
%{--网格--}%的标记
%{--寻呼机的标记--}%
我不确定我的控制器或视图中是否存在问题,以确定为什么我无法看到添加到网格中的数据。找出了为什么数据没有显示的问题所在。这是我的url和editUrl行。我原以为那是我希望数据进入的url,但却用listAllMobileSuits for url和editAllMobileSuits for editURl替换了它,这是我在控制器中的网格列表和编辑的函数名 如此转身
url: 'MobileSuits/mobileSuits',
editurl: 'MobileSuits/editAllMobileSuits',
进入
url: 'listAllMobileSuits',
editurl: 'editAllMobileSuits',