当前位置: 首页 > news >正文

dataTable 查询,重置

上源码

dataTable搜索function search(btn,grid)

dataTable重置

/**
 * 公共js组件 @all
 **/
//公共设置默认图片地址:
var commonImgAddress = "/assets/global/img/default.jpg";
/**
 *
 *docName   file组件的name
 *viewId  img的id
 *localId  div的id
 * imgWidth  img的宽度
 * imgHeight img的高度
 * divWidth div的宽度
 * divHeight div的高度
 */
function setImagePreview(docName,viewId,localId,imgWidth,imgHeight,divWidth,divHeight,tip){
    // return;
    $('#uploadFiletIcon').text('');
    var docObj=document.getElementById(docName); //"doc");
    var imgObjPreview=document.getElementById(viewId); //"preview");
    var fileObj=$('#'+docName).val();
    if(tip==1){
        $('#tip').val(1);
        $('#uploadFileIconx').val('');
        $('#uploadFileIcon').text('');
    }else{
        $('#iconTip').val(1);
    }
    if(fileObj){
        if(docObj.files&&docObj.files[0]){
            //火狐下,直接设img属性
            imgObjPreview.style.display='inline-block';
            imgObjPreview.style.width=imgWidth; //'60px';
            imgObjPreview.style.height=imgHeight; //'60px';
            //imgObjPreview.src = docObj.files[0].getAsDataURL();
            //火狐7以上版本不能用上面的getAsDataURL()方式获取,需要一下方式
            imgObjPreview.src=window.URL.createObjectURL(docObj.files[0]);
        }else{
            //IE下,使用滤镜
            docObj.select();
            var imgSrc=document.selection.createRange().text;
            var localImagId=document.getElementById(localId); //"localImag");
            //必须设置初始大小
            localImagId.style.width=divWidth; //"300px";
            localImagId.style.height=divHeight; //"120px";
            //图片异常的捕捉,防止用户修改后缀来伪造图片
            try{
                localImagId.style.filter="progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod=scale)";
                localImagId.filters.item("DXImageTransform.Microsoft.AlphaImageLoader").src=imgSrc;
            }catch(e){
                alert("您上传的图片格式不正确,请重新选择!");
                return false;
            }
            imgObjPreview.style.display='none';
            document.selection.empty();
        }
    }
    return true;
}
//图片格式
var extArray=new Array(".jpg",".jpeg",".png",".gif");
//压缩包格式
var zipArray=new Array(".zip",".rar");
/**
 * 判断上传文件的类型
 * @param file
 * @param tip
 * @returns {Boolean}
 */
function limitAttach(file,tip){
    var finaFile="";
    if(tip==1){
        finaFile=extArray;
    }else{
        finaFile=zipArray;
    }
    var allowSubmit=false;
    if(!file){
        allowSubmit=true;
    }
    while(file.indexOf("\\")!= -1){
        file=file.slice(file.indexOf("\\")+1);
    }
    var ext=file.slice(file.indexOf(".")).toLowerCase();
    for(var i=0; i<finaFile.length; i++){
        if(finaFile[i]==ext){
            allowSubmit=true;
            break;
        }
    }
    if(!allowSubmit){
        alert("只能上传以下格式的文件:"+(finaFile.join(""))+"\n 请重新选择再上传.");
        return false;
    }
    return allowSubmit;
}
/**
 * 全选 按钮
 * @param th
 * @param name
 */
function checkAllBox(th,name){
    if(th){
        if(th.checked){
            if(name){
                $("input[name='"+name+"']").attr("checked",true).parent('span').addClass('checked');
                $(th).parent("span").addClass("checked");
            }else{
                $("input[name='checkBox']").attr("checked",true).parent('span').addClass('checked');
            }
        }else{
            if(name){
                $(th).parent("span").removeClass("checked");
                $("input[name='"+name+"']").attr("checked",false).parent('span').removeClass('checked');
            }else{
                $("input[name='checkBox']").attr("checked",false).parent('span').removeClass('checked');
            }
        }
    }
}
/**
 * 格式化时间
 * @param objDate 需要格式化的时间
 * @returns clock 返回 2014-10-10 10:10:10
 */
function changeDate(objDate){
    var clock="";
    if(objDate!=null&&objDate){
        var now=new Date(objDate);
        var year=now.getFullYear();
        var month=now.getMonth()+1;
        var day=now.getDate();
        var hh=now.getHours();
        var mm=now.getMinutes();
        clock=year+"-";
        if(month<10)
            clock+="0";
        clock+=month+"-";
        if(day<10)
            clock+="0";
        clock+=day+" ";
        if(hh<10)
            clock+="0";
        clock+=hh+":";
        if(mm<10) clock+='0';
        clock+=mm;
        if(now.getSeconds()<10){
            clock+=":0"+now.getSeconds();
        }else{
            clock+=":"+now.getSeconds();
        }
    }
    return clock;
}
/**
 *  根据格式来格式化时间
 * @param format 格式化时间的格式 如 yyyy-MM-dd
 * @returns 返回 格式化后时间
 */

Date.prototype.format=function(format){
    var o={
        "M+":this.getMonth()+1, //month
        "d+":this.getDate(),    //day
        "h+":this.getHours(),   //hour
        "m+":this.getMinutes(), //minute
        "s+":this.getSeconds(), //second
        "q+":Math.floor((this.getMonth()+3)/3),  //quarter
        "S":this.getMilliseconds() //millisecond
    }
    if(/(y+)/.test(format)) format=format.replace(RegExp.$1,(this.getFullYear()+"").substr(4-RegExp.$1.length));
    for(var k in o)if(new RegExp("("+k+")").test(format))
        format=format.replace(RegExp.$1,RegExp.$1.length==1?o[k]:("00"+o[k]).substr((""+o[k]).length));
    return format;
}
//操作成功后的提示框,两秒钟后自动关闭
function alertHint(msg,callback){
    if(!msg){
        msg="操作成功.";
    }
    bootbox.alert(msg);
    setTimeout(function(){
        bootbox.hideAll();
        if(callback){
            callback();
        }
    },2000);
}
/**
 * 拼接字符串信息
 * @param num
 * @returns {Number}
 */
function factorial(obj,tip){
    var finstring;
    if(obj){
        if(obj.length<=tip){
            finstring=obj;
        }else{
            var temp=arguments.callee((obj.substring(tip,obj.length)),tip);
            finstring+=obj.substring(0,tip)+"</br>"+temp
        }
    }
    return finstring.replace("undefined","");
}
/**
 * 获取 http://localhost:8080
 */
function getURL(projoName){
    var curWwwPath=window.document.location.href;
    var pathName=window.document.location.pathname;
    var pos=curWwwPath.indexOf(pathName); //获取主机地址,如: http://localhost:8080
    var localhostPaht=curWwwPath.substring(0,pos); //获取带"/"的项目名,如:/cis
  /*   var projectName = pathName.substring(0, pathName.substr(1).indexOf('/') + 1);// TODO 不需要项目名称,注释掉
     var rootPath = localhostPaht + projectName;*/
    var finalName ;
    if(projoName){
        finalName =  localhostPaht+projoName;
    }else{
        finalName=localhostPaht;
    }
    return finalName;
}
/**
 * 获取上传文件的名字
 * @param obj
 * @param id
 */
function getFullPath(obj,id){
    if(obj){
        var path=obj.value;
        var index=path.lastIndexOf("\\")+1;
        if(index>0){
            $('#'+id).html(path.substr(index));
        }else{
            $('#'+id).html(path);
        }
    }
}

//dataTable搜索
function search(btn,grid){
    var search_div=$(btn).parent().parent("div");
    var inputs=search_div.find('input').filter(".form-filter");
    for(var i=0;i<inputs.length;i++){
        $(inputs[i]).val($(inputs[i]).val().trim());
    }
    grid.search(search_div);
}
//dataTable重置
function reset(btn,excludes,grid){
    var search_div=$(btn).parent().parent("div");
    grid.reset(search_div,excludes);
}

案例

<div id="data_table_search">
                    <label style="margin-left: 10px;">
                        编号:
                        <input type="text" class="form-filter input-sm" style="width: 120px;"
                               name="search_LIKE_contractCode">
                    </label>
                    <label style="margin-left: 10px;">
                        产品:
                        <input type="text" class="form-filter input-sm" style="width: 120px;" placeholder="产品"
                               name="search_LIKE_proName">
                    </label>
                    <label style="margin-left: 10px;">
                        状态:
                        <select name="search_AND_isreturn" id="isreturn" class="form-filter">
                            <option value="">所有</option>
                            <option value="N">待归还</option>
                            <option value="Y">已归还</option>
                        </select>
                    </label>
                    <label style="margin-left: 10px;">
                        超期:
                        <select name="search_AND_overdue" id="overdue" class="form-filter">
                            <option value="">所有</option>
                            <option value="Y"></option>
                            <option value="N"></option>
                        </select>
                    </label>


                    <label style="margin-left: 10px;">
                        <button class="btn btn-sm yellow margin-bottom filter-submit" value="搜索"
                                onclick="search(this,grid)"><i class="fa fa-search"></i> 搜索
                        </button>
                        <button class="btn btn-sm red filter-cancel" id="restSearch" onclick="reset(this,[],grid)"><i
                                class="fa fa-times"></i> 重置
                        </button>
                    </label>
                </div>

这里写图片描述

相关文章:

  • Jsoup学习总结
  • 工作步骤
  • linux分区,磁盘系统的管理,文件系统制作
  • H5上传图片前端预览显示
  • 大型企业网络配置系列课程详解(六) --PPP链路的配置与相关概念的理解
  • 2、使用vmware虚拟机安装Linux(以redhat5.8为例)中常见问题
  • C字符串与NSString之间的转换
  • 集合(三)CopyOnWriteArrayList
  • linux基础,zip、tar
  • http基本概述
  • 解决FTP服务器命令好使,工具不好使。
  • 学习计划与方法
  • go语言笔记——go环境变量goroot是安装了路径和gopath是三方包路径
  • What does AspCompat=true mean and when should I use it?
  • 使用ASP.Net WebAPI构建REST服务(三)——返回值
  • [译]CSS 居中(Center)方法大合集
  • 【翻译】Mashape是如何管理15000个API和微服务的(三)
  • ComponentOne 2017 V2版本正式发布
  • react-core-image-upload 一款轻量级图片上传裁剪插件
  • Synchronized 关键字使用、底层原理、JDK1.6 之后的底层优化以及 和ReenTrantLock 的对比...
  • Unix命令
  • 阿里云ubuntu14.04 Nginx反向代理Nodejs
  • 基于遗传算法的优化问题求解
  • 精彩代码 vue.js
  • 聊一聊前端的监控
  • 模型微调
  • 前端技术周刊 2018-12-10:前端自动化测试
  • 深度学习在携程攻略社区的应用
  • 微信小程序:实现悬浮返回和分享按钮
  • python最赚钱的4个方向,你最心动的是哪个?
  • ​ubuntu下安装kvm虚拟机
  • (007)XHTML文档之标题——h1~h6
  • (26)4.7 字符函数和字符串函数
  • (32位汇编 五)mov/add/sub/and/or/xor/not
  • (C++17) std算法之执行策略 execution
  • (附源码)php投票系统 毕业设计 121500
  • (附源码)ssm高校社团管理系统 毕业设计 234162
  • (附源码)计算机毕业设计ssm高校《大学语文》课程作业在线管理系统
  • (力扣记录)1448. 统计二叉树中好节点的数目
  • (欧拉)openEuler系统添加网卡文件配置流程、(欧拉)openEuler系统手动配置ipv6地址流程、(欧拉)openEuler系统网络管理说明
  • (五) 一起学 Unix 环境高级编程 (APUE) 之 进程环境
  • (转)ABI是什么
  • .NET : 在VS2008中计算代码度量值
  • .NET Core中Emit的使用
  • .net操作Excel出错解决
  • .NET程序员迈向卓越的必由之路
  • @Bean, @Component, @Configuration简析
  • @converter 只能用mysql吗_python-MySQLConverter对象没有mysql-connector属性’...
  • @serverendpoint注解_SpringBoot 使用WebSocket打造在线聊天室(基于注解)
  • [Android]Tool-Systrace
  • [AS3]URLLoader+URLRequest+JPGEncoder实现BitmapData图片数据保存
  • [C#]C# OpenVINO部署yolov8图像分类模型
  • [C/C++]关于C++11中的std::move和std::forward
  • [CareerCup] 6.1 Find Heavy Bottle 寻找重瓶子
  • [cb]UIGrid+UIStretch的自适应