2016-04-02 22 views
0

jqgrid'i yüklemeyi denediğimde, üstbilgiyi gösterir, ancak içindeki satırlardan hiçbirini eklemez. Burada resmin Bağlantı - Benim denetleyicisi veya görünümde bir sorun varsa> Image of problem I am havingjqgrid veri satırlarını göstermiyor

Kontrolör

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 

    } 
} 

Görünüm

<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> 

Emin değilim ızgaraya eklediğim verileri neden göremediğimi belirleyin.

cevap

0

Verilerin neden gösterilmediğiyle ilgili neyin yanlış olduğunu çözdünüz. Hem benim URL'm hem de editUrl satırlarımdı. Ben veri gitmek istedim url olduğunu düşündüm, ancak bunun yerine ben listenin fonksiyon adı vardı ve benim denetleyicide var ızgara için düzenlemek editURl için url ve editAllMobileSuits için listAllMobileSuits ile değiştirdi.

Yani

url: 'listAllMobileSuits', 
editurl: 'editAllMobileSuits', 
içine

url: 'MobileSuits/mobileSuits', 
editurl: 'MobileSuits/editAllMobileSuits', 

döndü