JQuery Kendo UI使用技巧总结

简介: JQuery Kendo UI使用技巧总结

Kendo UI开发总结 By Gloomyfish on 2013-04-25

Grid中支持分页刷新:          

scrollable: {virtual : true },

GridDataSource中添加分页支持:

serverPaging: true,


serverSorting: true,


serverFiltering: true,


pageSize: 50,



在grid中显示列(显示/隐藏菜单)与过滤支持菜单


filterable: true,


columnMenu: true,



在Grid中隐藏某个指定的列,需要在columns中指定column下面添加:


hidden:true,



使用模板来格式化显示grid中的列数据,给对应列添加模板的代码如下:


        template : "#=(value==-1) ? '-' :formatValue(value)#"



对齐显示grid中列文本的代码如下:


attributes:{ style: "text-align: right"}



绑定一个Kendo datasource到kendo.observable对象:


var formVM = kendo.observable({


    sources: formDS,


    source: null


});



绑定指定的formVM到某个Div元素:


kendo.bind($("#form_div"),formVM);



在页面数据改变时,更新绑定的数据源(DataSource):


formDS.bind("change", function() {


  //binds the view-model to the first entryin the datasource


  formVM.set("source", this.view()[0]);


});



强制更新form_div中的值:


formVM.set("source.userName", 'gloomyfish');对应的HTML为


<input id="uname"name="uname" data-bind="value: source.userName"/>



启动一个新的浏览器新窗口代码如下:


var left = (screen.width/2)-(800/2);


var top = 0;//(screen.height/2)-(800/2);


// force to open new widows in chrome,IE, FF


window.open("personInfo.html","_blank","resizable=yes, scrollbars=yes,titlebar=yes, width=800, height=800, top="+ top +", left="+ left);



下载grid中选中的所有文件:


var grid = $("#file_grid").data("kendoGrid");


var tr = grid.select(); //gets selected <tr> element          


if(tr.length >= 1) {      


       for(var i=0; i<tr.length;i++) {


            var item =grid.dataItem(tr[i]); //gets the dataSourceitem


            var fid = item.id;


           makeFrame("file/"+ fid +"/fileContent.htm");


       }


}


   function makeFrame( url )


   {


       var ifrm = document.createElement( "IFRAME");


       ifrm.setAttribute( "style", "display:none;") ;


       ifrm.setAttribute( "src", url ) ;


       ifrm.style.width = 0+"px";


       ifrm.style.height = 0+"px";


       document.body.appendChild( ifrm ) ;


   }



通过window.location或者window.location.href打开指定URL



同步Grid数据更新,使用如下代码:


grid.dataSource.sync()


或者


myGrid.dataSource.read();


myGrid.refresh();



一个Ajax请求跳转页面的例子:


  $.ajax({


       url : "openMyInfo",


       type : "POST",


       data : {userName: name, userId:id },        


       success : function(jqXHR, textStatus) {


           if (jqXHR.jsonResponse.success) {              


               var url = jqXHR.jsonResponse.message;


               window.location=url;          


           } else {


              alert(jqXHR.jsonResponse.message);


           }


       },


       error : function(jqXHR, textStatus, errorThrown) {


           alert (errorThrown);


       }


});



Kendo UI dropdown list级联菜单刷新:


在父dropdown list上绑定change事件函数:change : onItemChange


在函数中刷新更新子dropdow list的数据源(data source)


var subDDList = $('#subListDiv').data("kendoDropDownList");


subDDList.setDataSource(buildSubList(selectParentId));



上传文件对话框使用


  $("#selectedFiles").kendoUpload({


       async: {


           saveUrl: "myDomain/fileUpload.htm",


           autoUpload: true


       },


       multiple:true, // 支持多个文件上传,


       complete: uploadFileComplete, //上传结束以后处理,


       error: onError,


       cancel: onCancel,


       select: onSelect,


       success: onSuccess


});


调用代码 $("# selectedFiles ").click();//模拟鼠标双击事件调用,


页面上selectedFileshtml元素为隐藏对象。



禁用IE缓存,在JQuery1.2以上版本支持:


$.ajax({


   type:"GET",


   url:"static/cache.js",


   dataType:"text",


   cache:false, // disable cache(禁用IE缓存)


   ifModified:true


});



在HTML文件中加上:


<meta http-equiv="Expires"content="0"/>


<meta http-equiv="Cache-Control"content="no-cache"/>


<meta http-equiv="Pragma"content="no-cache"/>



提交数据之后打开在新窗口:


<form action="getMyInfo.htm"method="post" target="_blank">



获取Servlet的真是路径:


request.getSession().getServletContext().getRealPath("/");



实现路径重定向:


((HttpServletResponse)response).sendRedirect(redirectURL);



JS中替换反斜线正则表达式:


var myString = content.replace(/\//g, "\\\\");


或者:var value = value.replace(/\\/g, "whatever");



JQuery中报UncaughtSyntaxError: Unexpected identifier


原因多数是你在前一行少加了分号,或者使用了不恰当的关键字标识,比如


setTimeout(new function(){alert(“Helloworld”);}, 200);


其中new是多余关键字,导致错误。



隐藏页面上DIV内容:


$(my_div_id).css("display","none");  


显示它:


$(my_div_id).css("display","");



纯JavaScript方式实现,永远有效的隐藏一个DIV内容的方法:


document.getElementById('myDivID').style.display = 'none';


显示它:


document.getElementById('myDivID').style.display = '';

相关文章
|
JSON 前端开发 JavaScript
【前端】使用jQuery封装一套UI组件 - 级联选择器组件
本篇文章来讲解下级联选择器组件 级联选择器,在实际项目中也是比较常用的组件,比如:省市区三级关联,上下级联动等 最后面会附上全部代码
1246 0
|
1月前
|
开发者
jQuery.Deferred 在 SAP UI5 源代码中的应用分析
jQuery.Deferred 在 SAP UI5 源代码中的应用分析
|
7月前
jquery-easyui和jquery-ui的slider冲突解决
jquery-easyui和jquery-ui的slider冲突解决
|
10月前
|
前端开发 JavaScript
前端——Kendo UI的一些知识点
前端——Kendo UI的一些知识点
|
JavaScript 前端开发 程序员
【前端】使用jQuery封装一套UI组件 - 是和否滑动切换组件
本篇文章来讲解下是和否的滑动切换组件 切换滑动组件,使用的场景实际上就是一个开和关的场景,一般有是和否,开和关,禁用和启用等等,只需要设置0和1即可
127 0
|
JavaScript 前端开发 程序员
【前端】使用jQuery封装一套UI组件 - 可编辑下拉框组件
下拉框也是比较常用的组件,对应原生的下拉标签就是select 本篇文章就来讲讲可编辑下拉框组件的封装过程
335 0
|
JavaScript 前端开发 程序员
【前端】使用jQuery封装一套UI组件 - 移动端时间选择组件
【首先要声明一点,技术不分好坏,能用好就行,不用鄙视老技术】 今天要给大家展示的是移动端时间选择组件 最开始,看到比较新颖的移动端时间选择组件是在某款手机上,分年月日下拉选择,UI界面也挺好看的 除了讲解实现的步骤以及关键点,文章最后面会有完整的代码
215 0
|
前端开发 JavaScript 程序员
【前端】使用jQuery封装一套UI组件 - 单选框
目前前端技术发展非常快,各大厂都开源和分享了自家的前端框架,非常多成熟的UI组件供大家选择,很实用也很方便,给开发上节省了不少时间成本,当然少不了学习成本,不过也不会占用太多时间,只要有前端基础的话,原理基本都是通用的,只是写法不一样。 因此,除了学习现有的优秀前端之外,最好能自己根据原理封装一套自己的UI组件,目的是为了更好的理解前端知识点以及锻炼编程逻辑
144 0
|
1月前
|
前端开发 搜索推荐 开发者
SAP UI5 sap.m.Column 控件的 minScreenWidth 属性介绍
SAP UI5 sap.m.Column 控件的 minScreenWidth 属性介绍
|
1月前
|
JavaScript 前端开发 开发者
SAP UI5 控件 sap.m.ListBase 的 inset 属性的作用介绍
SAP UI5 控件 sap.m.ListBase 的 inset 属性的作用介绍