【发布时间】:2016-05-31 07:11:13
【问题描述】:
我只是跟着这个,但我的是在 php 中,
Show different Jqgrid formats in the same page 如果我从下拉列表中选择一个项目,我也想要相同类型的选项,除了少数之外,所有列都想要隐藏,特别是我不明白这一点以及如何在 php 中编写此代码
<table width="100%">
<tr>
<td>Tipo de Equipo :</td>
<td><% =Html.DropDownList("TipoId", (SelectList)ViewData["tiposdeEquipo"], "--Seleccione--", new { @id = "displaydropdown" })%> </td>
</tr>
<tr>
<td colspan="2"><input type="submit" value="Mostrar" /></td>
</tr>
</table>
点击Mostrar,此代码的工作原理,请帮助我,我是初学者。
这是我的代码
<select id="displaydropdown" name="displaydropdown">
<option selected>Change Type</option>
<option value="A">option1</option>
<option value="B">option2</option>
<option value="C">option3</option>
</select>
<div class="box A" align="center"><table id="jqGrid" ></table><div id="jqGridPager"></div></div>
<script type="text/javascript">
var lastsel;
$(function () {
$("#jqGrid").jqGrid({
url:'server.php',
editurl: 'update.php',
datatype: "json",
shrinkToFit: true,
colModel:[
{label:'COUNT',name:'ID',align:"center"},
{label:'EMPLOYEE LOGIN',name:'Employee_Login',align:"center"},
{label:'NEW LEAD',name:'New_Value',align:"center"},
{label:'REASON/COMMENTS',name:'Requestor_NOTES',align:"center"},
{label:'EXISTING LEAD',name:'Existing_Value',align:"center"},
],
rowNum:200,
rowList:[400,300,200],
onCellSelect: function (rowid, iCol, cellcontent, e) {
if (rowid && rowid !== lastsel) {
$('#jqGrid').restoreRow(lastsel);
lastsel = rowid;
}
$('#jqGrid').editRow(rowid, true, iCol);
},
pager: '#jqGridPager',
sortorder: "asc",
viewrecords: true,
height:'300px',
width:'750'
});
jQuery("#jqGrid").jqGrid('navGrid',"#jqGridPager",{edit:false,add:false,del:false,search:false});
//$('#jqGrid').jqGrid('setGridWidth', '1300');
});
$("#displaydropdown").change(function () {
var display = $("#displaydropdown option:selected").val();
if (display == 'A')
{
$('#jqGrid').hideCol('ID');
$('#jqGrid').showCol('Req_Date');
$('#jqGrid').showCol('App_WeekBeginning');
}
else if (display == 'B') {
$('#jqGrid').hideCol('App_WeekBeginning');
$('#jqGrid').showCol('Req_Day' );
$('#jqGrid').showCol('App_Week');
}
else if (display == 'C') {
$('#jqGrid').hideCol('App_Week')
$('#jqGrid').showCol('ID');
$('#jqGrid').showCol('Req_Date');
}
});
</script>
【问题讨论】:
-
您到底遇到了哪个问题(什么是行不通的)?代码
jQuery(document).ready(function () {...});和$(function () {...});执行相同:您不应该将一个等待文档准备就绪的代码放在另一个代码中。从url:'server.php'返回的数据是哪种格式(2-3 行的示例会有所帮助)?你不应该在colModel中使用包含空格(如'NEW LEAD')或特殊字符name:'EXISTING LEAD'的值的name属性。使用index属性是不好的。可能你想使用label: 'EMPLOYEE LOGIN', name: 'Req_Date'? -
在每个关于 jqGrid 的问题中都必须包含相关信息、您使用的 jqGrid 版本以及 jqGrid 的哪个分支(free jqGrid、商业 Guriddo jqGrid JS 或版本 the answer,它显示了在
beforeSelectRow和onSelectRow内部调用editRow和restoreRow以及使用savedRow参数而不是@987654348 的示例@. -
感谢@Oleg 的回复,我将从名称重命名为Label。我正在使用Guriddo jqGrid JS,
-
不客气!我开发了free jqGrid fork,建议你看看。基本信息描述here。免费的 jqGrid 代码与旧的 jqGrid 4.x 兼容,the old documentation 中描述的大多数功能都可以在免费的 jqGrid 中使用。 the wiki 和每个已发布版本的自述文件中描述了新功能。