如何基于url将数据加载到jqgrid中

时间:2014-01-08 09:38:35

标签: jquery jsp jqgrid

我想基于url将数据加载到jqgrid中。在edit mode中,我根据userId从以下方法获取数据。

url:'<%=request.getContextPath() %>/Admin/getAllUserOffersList/${userBean.userId }'

并在Addmode我从下面的网址

获取数据
url:'<%=request.getContextPath() %>/Admin/getAllOffersList/'

我根据userId检查if条件但是无法放置它,显示错误。

if (userBean.userId != null) {
    url:'<%=request.getContextPath() %>/Admin/getAllOffersList/';
} else {
    url:'<%=request.getContextPath() %>/Admin/getAllUserOffersList/${userBean.userId }';
}

当我在下面的代码中检查上面的条件时显示

  

令牌上的语法错误“:”,;预期

我只想使用一个网址

这是我的代码:

$(document).ready(function(){
//jqGrid
$("#userOffersList").jqGrid({

    url:'<%=request.getContextPath() %>/Admin/getAllOffersList/',
    url:'<%=request.getContextPath() %>/Admin/getAllUserOffersList/${userBean.userId }',
    datatype: "json",   
    colNames:['Select','Category','Offer Text','Provider Name'],
    colModel:[
        {name:'isSelect',index:'isSelect',formatter: "checkbox", formatoptions: {disabled : false},editable: true,edittype:"checkbox",editoptions:{value:'true:false', defaultValue: 'false'},sortable:false,width:50},
        {name:'category',index:'category',width:100},               
        {name:'offerText',index:'offerText',width:350},
        {name:'providerName',index:'providerName',width:250},
        ],
        rowNum:20,
        rowList:[10,20,30,40,50],
        rownumbers: true,  
        pager: '#pagerDiv',
        sortname: 'offerText',  
        viewrecords: true,  
        sortorder: "asc",
        autowidth:'true',
    });
    $('#gridContainer div:not(.ui-jqgrid-titlebar)').width("100%");
    $('.ui-jqgrid-bdiv').css('height', window.innerHeight * .55);
    $('#load_userOffersList').width("130");
    $("#userOffersList").jqGrid('navGrid','#pagerDiv',{edit:false,add:false,del:false});
    $(".inline").colorbox({inline:true, width:"20%"});
});

JSP页面

<div id="tabs-2">
    <div id="gridContainer" >
        <table id="userOffersList"></table>
        <div id="pagerDiv"></div>
    </div>              
</div>

1 个答案:

答案 0 :(得分:0)

请复制粘贴下面的代码并尝试这项工作。这应该清除所有语法错误:

$(document).ready(function () {
            //jqGrid
            $("#userOffersList").jqGrid({
                <c:choose>
                <c:when test="${not empty userBean.userId}">
                url: '${pageContext.request.contextPath}/Admin/getAllOffersList/',
                </c:when>
                <c:otherwise>
                url: '${pageContext.request.contextPath}/Admin/getAllUserOffersList/${userBean.userId}',
                </c:otherwise>
                </c:choose>
                datatype: "json",
                colNames: ['Select', 'Category', 'Offer Text', 'Provider Name'],
                colModel: [
                    {name: 'isSelect', index: 'isSelect', formatter: "checkbox", formatoptions: {disabled: false}, editable: true, edittype: "checkbox", editoptions: {value: 'true:false', defaultValue: 'false'}, sortable: false, width: 50},
                    {name: 'category', index: 'category', width: 100},
                    {name: 'offerText', index: 'offerText', width: 350},
                    {name: 'providerName', index: 'providerName', width: 250}
                ],
                rowNum: 20,
                rowList: [10, 20, 30, 40, 50],
                rownumbers: true,
                pager: '#pagerDiv',
                sortname: 'offerText',
                viewrecords: true,
                sortorder: "asc",
                autowidth: 'true'
            });


            $('#gridContainer div:not(.ui-jqgrid-titlebar)').width("100%");
            $('.ui-jqgrid-bdiv').css('height', window.innerHeight * .55);
            $('#load_userOffersList').width("130");
            $("#userOffersList").jqGrid('navGrid', '#pagerDiv', {edit: false, add: false, del: false});
            $(".inline").colorbox({inline: true, width: "20%"});
        });

请始终尝试使用 JSTL 而不是 scriptlet