2 yjwzsrzj YJWZSRZJ 于 2017.09.09 20:14 提问

js 页面搜索,在搜索框中输入了身份证,在页面中显示,数据是从后台取出的 5C
 $(function data(){
    $("#dg").edatagrid({
        pageList:[5,10,20],
        fitColumns :true,
        pageSize:5,
        url:'json.action',
        remoteSort: false,
        pagination:true,
        toolbar:'#toolbar',
        columns:[[
                  {field:'uid',title:'编号',width:80},
                  {field:'uname',title:'名字',width:80,editor:{type:'text',options: {required: true}}},
                  {field:'ucard',title:'身份证',width:80,editor:{type:'text',options: {required: true}}},
                  {field:'ugender',title:'性别',width:80,editor:{type:'text',options: {required: true}},sortable:true,formatter:function(value,index,row){
                      if(value==1){
                          return '男';
                      }else if(value==2){
                          return '女';
                      }
                  },
                  editor:{
                        type:'combobox',
                        options:{
                            valueField:'rstateid',
                            textField:'text',
                            url:'data',
                            panelHeight:'auto',
                            required:true,  
                            data:[{
                                 rstateid:1,
                                 text: '男'
                                 },{
                                rstateid: 2,
                                 text: '女',
                               }]
                        }}},
                  {field:'uphone',title:'电话',width:100,editor:{type:'text',options: {required: true}}},
                  {field:'ucount',title:'人住人数',width:100,editor:{type:'text',options: {required: true}}}
              ]]
    })
    var row = $('#dg').datagrid('reload');
}); 

 取数据的代码
 function doSearch(){
            var searchucard=document.getElementById("search").value;
            if(searchucard==""){
                alert("请输入身份证");
                return;
            }
            var nameLength=searchucard.length;
            var table = document.getElementById("dg");
            var resultTable=document.getElementById("dg");
            var rowsLength = table.rows.length;
            var resultLength=resultTable.rows.length;
            while(resultLength>1){
                resultTable.deleteRow(resultLength-1);
                resultLength--;
            }
             for(i=1;i<rowsLength;i++){
             //根据姓名搜索
                 if(searchucard!=""){
                 //找到姓名那一列
                    var searchucard=table.rows[i].cells[1].innerText;
                   console.log(searchucard); 
                    var cellsLength=table.rows[i].cells.length;
                   console.log(cellsLength); 
                      //alert(cellsLength);
                    if(searchucard==ucard.substring(0,nameLength)){
                        var currentRow=resultTable.rows.length;
                        var NewRow=resultTable.insertRow(currentRow);
                        for(j=0;j<cellsLength;++j){
                            newCell=NewRow.insertCell(j);                   
                            newCell.innerText= table.rows[i].cells[j].innerText;
                        }
                    }
                }
         } 
    自己写了一点实现不了

急急急,求大神,一开始我用的是数据库取值的可以,后来觉得这中方法比较好,就想这样做,可是实习不了

2个回答

YJWZSRZJ
YJWZSRZJ   2017.09.10 08:45

自己顶一下,不会?????、

showbo
showbo   Ds   Rxr 2017.09.10 12:05

edatagrid是什么鬼?easyUI的datagrid吧。。你要更新数据用realod方法添加查询参数。获取数据是getRows,不是reload

清空数据行也不要直接操作easyUI的dom对象,都不是原来的table对象了,loadData加载空数组就能清空了
$('#dg').datagrid('loadData',[])

 reload     param   Reload the rows. Same as the 'load' method but stay on current page.
Csdn user default icon
上传中...
上传图片
插入图片