js插件再次封装 demo

'use strict';

/**
* commerce grid框架
* 依赖jqgrid
*/ (function ($_self, jQuery) { //jQuery.ajaxSetup({cache: false}); var _this = $_self; /**
* 底层核心列表
* @param grid_selector gird选择器
* @param pager_selector 分页器选择器
* @param loadUrl 数据加载url
* @param editUrl 数据操作url
* @param colNames 列名数组
* @param colModel 列模型数组
* @param gridComplete 数据完成后函数
* @param subGrid 是否开启子grid
* @param subGridOptions 子grid配置
* @param subGridRowExpanded zigrid Row展开
* @param caption 标题
*
*
* var colModel = [{
* name: 'name',
* //是否可编辑
* editable: true,
* //编辑的一系列选项
* //edittype:'select', editoptions:{value:{1:'One',2:'Two'}}
* //editoptions: {multiple:true, size:3... }
* //editoptions: {size:10, maxlength: 8}
* //editoptions: { size: 10, readonly: 'readonly'},
* editoptions: {
* //readonly: 'readonly',
* disabled: true
* },
* //编辑规则
* // edithidden:true只在Form Editing模式下有效,设置为true,就可以让隐藏字段也可以修改
* // required:true,number:true,integer:true,minValue:10,maxValue:100,email:true,url:true,date:true,time:true,custom:true,custom_func:function(){}}
* editrules: {},
* //编辑类型 text, textarea, select, checkbox, password, button, image and file.
* edittype: 'text',
* //列宽度是否要固定不可变
* fixed: false,
* hidedlg: true,
* //在初始化表格时是否要隐藏此列
* hidden: false,
* //是否可以被resizable
* //resizable: true,
* //在搜索模式下,定义此列是否可以作为搜索列
* search: false,
* //是否可排序
* sortable: false,
* width: 150,
* datefmt: 'yyyy-MM-dd',
* //left,center,right
* align: 'left'
* }
* ];
*
*
*
*
*/
var _coreGrid = function (grid_selector, pager_selector, loadUrl, editUrl, colNames, colModel, gridComplete, subGrid, subGridOptions, subGridRowExpanded, caption, treeGrid, expandColumn, multiselect, onSelectRow) {
jQuery(grid_selector).jqGrid({
url: loadUrl,
//ajaxGridOptions: {contentType: 'application/x-www-form-urlencoded; charset=utf-8'},
//ajaxSelectOptions: {contentType: 'application/json; charset=utf-8'},
//editoptions: {contentType: 'application/json; charset=utf-8'},
datatype: "json",
height: '100%',
autowidth: true,
colNames: colNames,
colModel: colModel,
viewrecords: true,
rowNum: 10,
rowList: [10, 20, 30],
pager: pager_selector,
altRows: true,
//toppager: true, multiselect: multiselect || false,
multiboxonly: multiselect || false,
beforeSelectRow: function (rowid, e) {
if (multiselect) {
var $myGrid = jQuery(this),
i = jQuery.jgrid.getCellIndex(jQuery(e.target).closest('td')[0]),
cm = $myGrid.jqGrid('getGridParam', 'colModel');
return (cm[i].name === 'cb');
}
return true;
}, jsonReader: {
root: "body.records",
page: "body.pageNo",
total: "body.pages",
records: "body.total",
repeatitems: false
}, emptyrecords: '没有记录显示',
loadComplete: function () {
var table = this;
setTimeout(function () {
styleCheckbox(table);
updateActionIcons(table);
updatePagerIcons(table);
enableTooltips(table);
}, 0);
},
gridComplete: gridComplete || function () {
},
editurl: editUrl,
onSelectRow: onSelectRow || function () {
}, //subGrid
subGrid: subGrid || false,
subGridOptions: subGridOptions || {},
subGridRowExpanded: subGridRowExpanded || function () {
},
caption: caption || '', //treeGrid
treeGrid: treeGrid || false,
treeGridModel: 'adjacency',
ExpandColClick: true,
ExpandColumn: expandColumn || 'id',
treeIcons: {
plus: 'ace-icon fa fa-caret-right bigger-160 blue',
minus: 'ace-icon fa fa-caret-down bigger-160 blue',
leaf: 'ace-icon fa fa-tags orange'
}//树图标
}); //自适应
_this.resize(grid_selector);
//_this.addFun(grid_selector); }; /**
* 选中数据
* @param grid
* @param id
*/
_this.setSelectData = function (grid_selector, ids) {
var _ids = ids || [];
var grid = jQuery(grid_selector);
for (var i = 0; i < _ids.length; i++) {
grid.jqGrid("setSelection", _ids[i]);
}
}; _this.reloadGrid = function (grid_selector) {
$(grid_selector).trigger('reloadGrid');
}; /**
* 简单crud列表
*/
_this.crudGrid = function (grid_selector, pager_selector, loadUrl, editUrl, colNames, colModel) {
_coreGrid(grid_selector, pager_selector, loadUrl, editUrl, colNames, colModel);
_this.navButtons(grid_selector, pager_selector, colModel);
}; /**
* 树列表
*/
_this.treeGrid = function (grid_selector, pager_selector, loadUrl, editUrl, colNames, colModel, expandColumn) {
_coreGrid(grid_selector, pager_selector, loadUrl, editUrl, colNames, colModel, '', false, '', '', '', true, expandColumn);
_this.navButtons(grid_selector, pager_selector, colModel);
}; /**
* 定制操作列表
* navButtons : {add: true, del: true, edit: true, view: true, search: true};
*/
_this.treeNavGrid = function (grid_selector, pager_selector, loadUrl, editUrl, colNames, colModel, navButtons, expandColumn) {
_coreGrid(grid_selector, pager_selector, loadUrl, editUrl, colNames, colModel, '', false, '', '', '', true, expandColumn);
_this.navButtons(grid_selector, pager_selector, colModel, navButtons);
}; /**
* 定制操作tree列表
* navButtons : {add: true, del: true, edit: true, view: true, search: true};
*/
_this.operTreeNavGrid = function (grid_selector, pager_selector, loadUrl, editUrl, colNames, colModel, navButtons, expandColumn, opers) {
var gridComplete = function () {
var grid = jQuery(grid_selector);
var ids = grid.jqGrid('getDataIDs');
for (var i = 0, j = ids.length; i < j; i++) {
var cl = ids[i];
var opers_button = '';
for (var m = 0, n = opers.length; m < n; m++) {
opers_button += "<input type='button' value='" + opers[m].oper + "' onclick=\"(" + opers[m].action + ")(" + cl + ")\">";
}
grid.jqGrid('setRowData', cl, {operation: opers_button});
}
};
_coreGrid(grid_selector, pager_selector, loadUrl, editUrl, colNames, colModel, gridComplete, false, '', '', '', true, expandColumn);
_this.navButtons(grid_selector, pager_selector, colModel, navButtons);
}; /**
* 数据行带操作按钮的列表
* {
name: 'operation',
width: 80,
fixed: true,
sortable: false,
resize: false
}
* opers : [{oper:'发布',action:function}]
*/
_this.operGrid = function (grid_selector, pager_selector, loadUrl, editUrl, colNames, colModel, opers) {
var gridComplete = function () {
var grid = jQuery(grid_selector);
var ids = grid.jqGrid('getDataIDs');
for (var i = 0, j = ids.length; i < j; i++) {
var cl = ids[i];
var opers_button = '';
for (var m = 0, n = opers.length; m < n; m++) {
opers_button += "<input type='button' value='" + opers[m].oper + "' onclick=\"(" + opers[m].action + ")(" + cl + ")\">";
}
grid.jqGrid('setRowData', cl, {operation: opers_button});
}
};
_coreGrid(grid_selector, pager_selector, loadUrl, editUrl, colNames, colModel, gridComplete);
_this.navButtons(grid_selector, pager_selector, colModel);
}; /**
* 数据行带操作按钮的列表并定制操作
*/
_this.operNavGrid = function (grid_selector, pager_selector, loadUrl, editUrl, colNames, colModel, opers, navButtons) {
var gridComplete = function () {
var grid = jQuery(grid_selector);
var ids = grid.jqGrid('getDataIDs');
for (var i = 0, j = ids.length; i < j; i++) {
var cl = ids[i];
var opers_button = '';
for (var m = 0, n = opers.length; m < n; m++) {
opers_button += "<input type='button' value='" + opers[m].oper + "' onclick=\"(" + opers[m].action + ")(" + cl + ")\">";
}
grid.jqGrid('setRowData', cl, {operation: opers_button});
}
};
_coreGrid(grid_selector, pager_selector, loadUrl, editUrl, colNames, colModel, gridComplete);
_this.navButtons(grid_selector, pager_selector, colModel, navButtons);
}; /**
* 定制操作列表
* navButtons : {add: true, del: true, edit: true, view: true, search: true};
*/
_this.navGrid = function (grid_selector, pager_selector, loadUrl, editUrl, colNames, colModel, navButtons, gridComplete) {
_coreGrid(grid_selector, pager_selector, loadUrl, editUrl, colNames, colModel, gridComplete);
_this.navButtons(grid_selector, pager_selector, colModel, navButtons);
}; /**
* 定制多选操作列表
* navButtons : {add: true, del: true, edit: true, view: true, search: true};
*/
_this.navSelectGrid = function (grid_selector, pager_selector, loadUrl, editUrl, colNames, colModel, navButtons, gridComplete, onSelectRow) {
_coreGrid(grid_selector, pager_selector, loadUrl, editUrl, colNames, colModel, gridComplete, '', '', '', '', '', '', true, onSelectRow);
_this.navButtons(grid_selector, pager_selector, colModel, navButtons);
}; /**
* 定制多选操作父子列表
* navButtons : {add: true, del: true, edit: true, view: true, search: true};
*/
_this.navSelectHasSubGrid = function (grid_selector, pager_selector, loadUrl, editUrl, colNames, colModel, navButtons, subLoadUrl, subEditUrl, subColNames, subColModel, subNavButtons, isShowSubHeader, gridComplete, onSelectRow) {
_this.hasNavSubGrid(grid_selector, pager_selector, loadUrl, editUrl, colNames, colModel, navButtons, subLoadUrl, subEditUrl, subColNames, subColModel, subNavButtons, gridComplete, isShowSubHeader, true, onSelectRow);
_this.navButtons(grid_selector, pager_selector, colModel, navButtons);
}; /**
* 父数据行带操作按钮的列表
* {
name: 'operation',
width: 80,
fixed: true,
sortable: false,
resize: false
}
* opers : [{oper:'发布',action:function}]
*/
_this.operHasSubGrid = function (grid_selector, pager_selector, loadUrl, editUrl, colNames, colModel, subLoadUrl, subEditUrl, subColNames, subColModel, opers, isShowSubHeader) {
_this.operHasNavSubGrid(grid_selector, pager_selector, loadUrl, editUrl, colNames, colModel, '', subLoadUrl, subEditUrl, subColNames, subColModel, '', opers, isShowSubHeader);
}; /**
* 定制操作列表[父数据行带操作按钮的列表]
* navButtons : {add: true, del: true, edit: true, view: true, search: true};
* subNavButtons : {add: true, del: true, edit: true, view: true, search: true};
*/
_this.operHasNavSubGrid = function (grid_selector, pager_selector, loadUrl, editUrl, colNames, colModel, navButtons, subLoadUrl, subEditUrl, subColNames, subColModel, subNavButtons, opers, isShowSubHeader) {
var gridComplete = function () {
var grid = jQuery(grid_selector);
var ids = grid.jqGrid('getDataIDs');
for (var i = 0, j = ids.length; i < j; i++) {
var cl = ids[i];
var opers_button = '';
for (var m = 0, n = opers.length; m < n; m++) {
opers_button += "<input type='button' value='" + opers[m].oper + "' onclick=\"(" + opers[m].action + ")(" + cl + ")\">";
}
grid.jqGrid('setRowData', cl, {operation: opers_button});
}
};
_this.hasNavSubGrid(grid_selector, pager_selector, loadUrl, editUrl, colNames, colModel, navButtons, subLoadUrl, subEditUrl, subColNames, subColModel, subNavButtons, gridComplete, isShowSubHeader);
}; /**
* 含有子列表的列表
*/
_this.hasSubGrid = function (grid_selector, pager_selector, loadUrl, editUrl, colNames, colModel, subLoadUrl, subEditUrl, subColNames, subColModel) {
_this.hasNavSubGrid(grid_selector, pager_selector, loadUrl, editUrl, colNames, colModel, '', subLoadUrl, subEditUrl, subColNames, subColModel);
}; /**
* 定制操作列表
* navButtons : {add: true, del: true, edit: true, view: true, search: true};
* subNavButtons : {add: true, del: true, edit: true, view: true, search: true};
*/
_this.hasNavSubGrid = function (grid_selector, pager_selector, loadUrl, editUrl, colNames, colModel, navButtons, subLoadUrl, subEditUrl, subColNames, subColModel, subNavButtons, gridComplete, isShowSubHeader, multiselect, onSelectRow) {
var subGridOptions = {
plusicon: "ace-icon fa fa-plus center bigger-110 blue",
minusicon: "ace-icon fa fa-minus center bigger-110 blue",
openicon: "ace-icon fa fa-chevron-right center orange"
};
var subGridRowExpanded = function (subgrid_id, row_id) {
var subgrid_table_id = subgrid_id + "_t";
var subgrid_pager_id = subgrid_id + '_pgr';
jQuery("#" + subgrid_id).html("<table id='" + subgrid_table_id + "' class='scroll'></table><div id='" + subgrid_pager_id + "' class='scroll'></div>"); var _subLoadUrl = subLoadUrl.indexOf('?') == -1 ? (subLoadUrl + '?rid=' + row_id) : (subLoadUrl + '&rid=' + row_id);
var _subEditUrl = subEditUrl.indexOf('?') == -1 ? (subEditUrl + '?rid=' + row_id) : (subEditUrl + '&rid=' + row_id);
_coreGrid('#' + subgrid_table_id, '#' + subgrid_pager_id, _subLoadUrl, _subEditUrl, subColNames, subColModel); if (!isShowSubHeader) {
jQuery(".ui-subgrid").find(".ui-jqgrid-htable").hide(); } _this.navButtons('#' + subgrid_table_id, '#' + subgrid_pager_id, subColModel, subNavButtons);
};
_coreGrid(grid_selector, pager_selector, loadUrl, editUrl, colNames, colModel, gridComplete, true, subGridOptions, subGridRowExpanded, '', '', '', multiselect, onSelectRow); _this.navButtons(grid_selector, pager_selector, colModel, navButtons);
}; /**
* 含有子列表
*/
_this.hasSubList = function (grid_selector, pager_selector, loadUrl, editUrl, colNames, colModel, subLoadUrl, subColModel, subColNames, isShowSubHeader) {
_this.hasNavSubList(grid_selector, pager_selector, loadUrl, editUrl, colNames, colModel, '', subLoadUrl, subColModel, subColNames, isShowSubHeader);
}; /**
* 父数据行带操作按钮的列表
* {
name: 'operation',
width: 80,
fixed: true,
sortable: false,
resize: false
}
* opers : [{oper:'发布',action:function}]
*/
_this.operHasNavSubList = function (grid_selector, pager_selector, loadUrl, editUrl, colNames, colModel, navButtons, subLoadUrl, subColModel, subColNames, opers, isShowSubHeader) {
var gridComplete = function () {
var grid = jQuery(grid_selector);
var ids = grid.jqGrid('getDataIDs');
for (var i = 0, j = ids.length; i < j; i++) {
var cl = ids[i];
var opers_button = '';
for (var m = 0, n = opers.length; m < n; m++) {
opers_button += "<input type='button' value='" + opers[m].oper + "' onclick=\"(" + opers[m].action + ")(" + cl + ")\">";
}
grid.jqGrid('setRowData', cl, {operation: opers_button});
}
};
_this.hasNavSubList(grid_selector, pager_selector, loadUrl, editUrl, colNames, colModel, navButtons, subLoadUrl, subColModel, subColNames, gridComplete, isShowSubHeader);
}; /**
* 定制操作列表
* navButtons : {add: true, del: true, edit: true, view: true, search: true};
*/
_this.hasNavSubList = function (grid_selector, pager_selector, loadUrl, editUrl, colNames, colModel, navButtons, subLoadUrl, subColModel, subColNames, gridComplete, isShowSubHeader,multiselect,onSelectRow) {
var subGridOptions = {
plusicon: "ace-icon fa fa-plus center bigger-110 blue",
minusicon: "ace-icon fa fa-minus center bigger-110 blue",
openicon: "ace-icon fa fa-chevron-right center orange"
};
var subGridRowExpanded = function (subgrid_id, row_id) {
var subgrid_table_id = subgrid_id + "_t";
jQuery("#" + subgrid_id).html("<table id='" + subgrid_table_id + "' class='scroll'></table>");
var _subLoadUrl = subLoadUrl.indexOf('?') == -1 ? (subLoadUrl + '?rid=' + row_id) : (subLoadUrl + '&rid=' + row_id); _coreGrid('#' + subgrid_table_id, '', _subLoadUrl, '', subColNames, subColModel); if (!isShowSubHeader) {
jQuery(".ui-subgrid").find(".ui-jqgrid-htable").hide(); }
};
_coreGrid(grid_selector, pager_selector, loadUrl, editUrl, colNames, colModel, gridComplete, true, subGridOptions, subGridRowExpanded,'','','',multiselect,onSelectRow);
_this.navButtons(grid_selector, pager_selector, colModel, navButtons);
}; //操作按钮组函数
_this.navButtons = function (grid_selector, pager_selector, colModel, navButtons) {
//navButtons
var _navButtons = navButtons || {add: true, del: true, edit: true, view: true, search: false};
jQuery(grid_selector).jqGrid('navGrid', pager_selector,
{ //navbar options
edit: _navButtons.edit,
editicon: 'ace-icon fa fa-pencil blue',
add: _navButtons.add,
addicon: 'ace-icon fa fa-plus-circle purple',
del: _navButtons.del,
delicon: 'ace-icon fa fa-trash-o red',
search: _navButtons.search,
searchicon: 'ace-icon fa fa-search orange',
refresh: true,
refreshicon: 'ace-icon fa fa-refresh green',
view: _navButtons.view,
viewicon: 'ace-icon fa fa-search-plus grey'
},
{
//编辑记录 表单
//closeAfterEdit: true,
//width: 700,
recreateForm: true,
beforeShowForm: function (e) {
var form = $(e[0]);
form.closest('.ui-jqdialog').find('.ui-jqdialog-titlebar').wrapInner('<div class="widget-header" />')
style_edit_form(form);
},
afterSubmit: function (data, postdata, oper) {
var response = data.responseJSON;
if (response.hasOwnProperty("error")) {
if (response.error.length) {
return [false, response.error];
}
}
return [true, "", ""];
},
errorTextFormat: function (data) {
return 'Error: ' + data.responseText
}
},
{
//新建记录 表单
//width: 700,
closeAfterAdd: true,
recreateForm: true,
viewPagerButtons: false,
beforeShowForm: function (e) {
//设置tree parent
//var parent = jQuery('#parent');
//if (parent && parent.length) {
// var id = jQuery(grid_selector).jqGrid('getGridParam', 'selrow');
// if (id) {
// jQuery('#parent').val(id);
// }
//} for (var i = 0, j = colModel.length; i < j; i++) {
e.find('#' + colModel[i].name).attr('disabled', false);
}
var form = $(e[0]);
form.closest('.ui-jqdialog').find('.ui-jqdialog-titlebar')
.wrapInner('<div class="widget-header" />');
style_edit_form(form);
},
afterSubmit: function (data, postdata, oper) {
var response = data.responseJSON;
if (response.hasOwnProperty("error")) {
if (response.error.length) {
return [false, response.error];
}
}
return [true, "", ""];
},
errorTextFormat: function (data) {
var response = jQuery.parseJSON(data.responseText);
return '错误: ' + response.body;
}
},
{
//删除记录 表单
recreateForm: true,
beforeShowForm: function (e) {
var form = $(e[0]);
if (form.data('styled')) return false; form.closest('.ui-jqdialog').find('.ui-jqdialog-titlebar').wrapInner('<div class="widget-header" />')
style_delete_form(form); form.data('styled', true);
},
afterSubmit: function (data, postdata, oper) {
var response = data.responseJSON;
if (response.hasOwnProperty("error")) {
if (response.error.length) {
return [false, response.error];
}
}
return [true, "", ""];
},
errorTextFormat: function (data) {
return 'Error: ' + data.responseText
}
},
{
//搜索 表单
recreateForm: true,
afterShowSearch: function (e) {
var form = $(e[0]);
form.closest('.ui-jqdialog').find('.ui-jqdialog-title').wrap('<div class="widget-header" />')
style_search_form(form);
},
afterRedraw: function () {
style_search_filters($(this));
}
,
multipleSearch: true
/**
multipleGroup:true,
showQuery: true
*/
},
{
//查看记录 表单
recreateForm: true,
beforeShowForm: function (e) {
var form = $(e[0]);
form.closest('.ui-jqdialog').find('.ui-jqdialog-title').wrap('<div class="widget-header" />')
},
afterSubmit: function (data, postdata, oper) {
var response = data.responseJSON;
if (response.hasOwnProperty("error")) {
if (response.error.length) {
return [false, response.error];
}
}
return [true, "", ""];
},
errorTextFormat: function (data) {
return 'Error: ' + data.responseText
}
}
);
}; //自适应
_this.resize = function (grid_selector) {
//拉伸缩小时适应当前页面
$(window).on('resize.jqGrid', function () {
$(grid_selector).jqGrid('setGridWidth', $(".page-content").width());
})
//当前侧边栏隐藏显示/缩小时拉伸/缩小jqgrid
var parent_column = $(grid_selector).closest('[class*="col-"]');
$(document).on('settings.ace.jqGrid', function (ev, event_name, collapsed) {
if (event_name === 'sidebar_collapsed' || event_name === 'main_container_fixed') {
//setTimeout is for webkit only to give time for DOM changes and then redraw!!!
setTimeout(function () {
$(grid_selector).jqGrid('setGridWidth', parent_column.width());
}, 0);
}
}) //if your grid is inside another element, for example a tab pane, you should use its parent's width:
/**
$(window).on('resize.jqGrid', function () {
var parent_width = $(grid_selector).closest('.tab-pane').width();
$(grid_selector).jqGrid( 'setGridWidth', parent_width );
})
//and also set width when tab pane becomes visible
$('#myTab a[data-toggle="tab"]').on('shown.bs.tab', function (e) {
if($(e.target).attr('href') == '#mygrid') {
var parent_width = $(grid_selector).closest('.tab-pane').width();
$(grid_selector).jqGrid( 'setGridWidth', parent_width );
}
})
*/ $(window).triggerHandler('resize.jqGrid');//trigger window resize to make the grid get the correct size }; //添加辅助函数
_this.addFun = function (grid_selector) {
//enable search/filter toolbar
//jQuery(grid_selector).jqGrid('filterToolbar',{defaultSearch:true,stringResult:true})
//jQuery(grid_selector).filterToolbar({}); //var selr = jQuery(grid_selector).jqGrid('getGridParam','selrow'); $(document).one('ajaxloadstart.page', function (e) {
$(grid_selector).jqGrid('GridUnload');
$('.ui-jqdialog').remove();
});
}; //datepicker 时间控件
_this.datepicker = function (cellvalue, options, cell) {
setTimeout(function () { $.fn.datepicker.dates['zh'] = {
days: ["星期天", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"],
daysShort: ["星期天", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"],
daysMin: ["天", "一", "二", "三", "四", "五", "六"],
months: ["一月", "二月", "三月", "四月", "五岳", "六月", "七月", "八月", "九月", "十月", "十一月", "十二月"],
monthsShort: ["一月", "二月", "三月", "四月", "五岳", "六月", "七月", "八月", "九月", "十月", "十一月", "十二月"],
today: "今天",
clear: "Clear",
format: "yyyy年mm月dd日",
titleFormat: "yyyy MM",
weekStart: 0
}; $(cell).find('input[type=text]')
.datepicker({
format: 'yyyy-mm-dd',
autoclose: 'true',
startDate: '0d',
disableTouchKeyboard: 'true',
language: 'zh'
});
}, 0);
}; //样式定制函数开始 //switch element when editing inline
function aceSwitch(cellvalue, options, cell) {
setTimeout(function () {
$(cell).find('input[type=checkbox]')
.addClass('ace ace-switch ace-switch-5')
.after('<span class="lbl"></span>');
}, 0);
} function style_edit_form(form) {
//enable datepicker on "sdate" field and switches for "stock" field
form.find('input[name=sdate]').datepicker({format: 'yyyy-mm-dd', autoclose: true}) form.find('input[name=stock]').addClass('ace ace-switch ace-switch-5').after('<span class="lbl"></span>');
//don't wrap inside a label element, the checkbox value won't be submitted (POST'ed)
//.addClass('ace ace-switch ace-switch-5').wrap('<label class="inline" />').after('<span class="lbl"></span>'); //update buttons classes
var buttons = form.next().find('.EditButton .fm-button');
buttons.addClass('btn btn-sm').find('[class*="-icon"]').hide();//ui-icon, s-icon
buttons.eq(0).addClass('btn-primary').prepend('<i class="ace-icon fa fa-check"></i>');
buttons.eq(1).prepend('<i class="ace-icon fa fa-times"></i>') buttons = form.next().find('.navButton a');
buttons.find('.ui-icon').hide();
buttons.eq(0).append('<i class="ace-icon fa fa-chevron-left"></i>');
buttons.eq(1).append('<i class="ace-icon fa fa-chevron-right"></i>');
} function style_delete_form(form) {
var buttons = form.next().find('.EditButton .fm-button');
buttons.addClass('btn btn-sm btn-white btn-round').find('[class*="-icon"]').hide();//ui-icon, s-icon
buttons.eq(0).addClass('btn-danger').prepend('<i class="ace-icon fa fa-trash-o"></i>');
buttons.eq(1).addClass('btn-default').prepend('<i class="ace-icon fa fa-times"></i>')
} function style_search_filters(form) {
form.find('.delete-rule').val('X');
form.find('.add-rule').addClass('btn btn-xs btn-primary');
form.find('.add-group').addClass('btn btn-xs btn-success');
form.find('.delete-group').addClass('btn btn-xs btn-danger');
} function style_search_form(form) {
var dialog = form.closest('.ui-jqdialog');
var buttons = dialog.find('.EditTable')
buttons.find('.EditButton a[id*="_reset"]').addClass('btn btn-sm btn-info').find('.ui-icon').attr('class', 'ace-icon fa fa-retweet');
buttons.find('.EditButton a[id*="_query"]').addClass('btn btn-sm btn-inverse').find('.ui-icon').attr('class', 'ace-icon fa fa-comment-o');
buttons.find('.EditButton a[id*="_search"]').addClass('btn btn-sm btn-purple').find('.ui-icon').attr('class', 'ace-icon fa fa-search');
} function beforeDeleteCallback(e) {
var form = $(e[0]);
if (form.data('styled')) return false; form.closest('.ui-jqdialog').find('.ui-jqdialog-titlebar').wrapInner('<div class="widget-header" />')
style_delete_form(form); form.data('styled', true);
} function beforeEditCallback(e) {
var form = $(e[0]);
form.closest('.ui-jqdialog').find('.ui-jqdialog-titlebar').wrapInner('<div class="widget-header" />')
style_edit_form(form);
} //it causes some flicker when reloading or navigating grid
//it may be possible to have some custom formatter to do this as the grid is being created to prevent this
//or go back to default browser checkbox styles for the grid
function styleCheckbox(table) {
/**
$(table).find('input:checkbox').addClass('ace')
.wrap('<label />')
.after('<span class="lbl align-top" />') $('.ui-jqgrid-labels th[id*="_cb"]:first-child')
.find('input.cbox[type=checkbox]').addClass('ace')
.wrap('<label />').after('<span class="lbl align-top" />');
*/
} //unlike navButtons icons, action icons in rows seem to be hard-coded
//you can change them like this in here if you want
function updateActionIcons(table) {
/**
var replacement =
{
'ui-ace-icon fa fa-pencil' : 'ace-icon fa fa-pencil blue',
'ui-ace-icon fa fa-trash-o' : 'ace-icon fa fa-trash-o red',
'ui-icon-disk' : 'ace-icon fa fa-check green',
'ui-icon-cancel' : 'ace-icon fa fa-times red'
};
$(table).find('.ui-pg-div span.ui-icon').each(function(){
var icon = $(this);
var $class = $.trim(icon.attr('class').replace('ui-icon', ''));
if($class in replacement) icon.attr('class', 'ui-icon '+replacement[$class]);
})
*/
} //replace icons with FontAwesome icons like above
function updatePagerIcons(table) {
var replacement =
{
'ui-icon-seek-first': 'ace-icon fa fa-angle-double-left bigger-140',
'ui-icon-seek-prev': 'ace-icon fa fa-angle-left bigger-140',
'ui-icon-seek-next': 'ace-icon fa fa-angle-right bigger-140',
'ui-icon-seek-end': 'ace-icon fa fa-angle-double-right bigger-140'
};
$('.ui-pg-table:not(.navtable) > tbody > tr > .ui-pg-button > .ui-icon').each(function () {
var icon = $(this);
var $class = $.trim(icon.attr('class').replace('ui-icon', '')); if ($class in replacement) icon.attr('class', 'ui-icon ' + replacement[$class]);
})
} function enableTooltips(table) {
$('.navtable .ui-pg-button').tooltip({container: 'body'});
$(table).find('.ui-pg-div').tooltip({container: 'body'});
} //样式定制函数结束 })(window.cgrid = {}, jQuery);
  

  

javascript笔记——jqGrid再次封装的更多相关文章

  1. javascript笔记——jqGrid 格式化时间列

    { name:'startTime', sortable:false, editable:true, width:300, sorttype:'date', //unformat:startTime, ...

  2. [Effective JavaScript 笔记]第27条:使用闭包而不是字符串来封装代码

    函数是一种将代码作为数据结构存储的便利方式,代码之后可以被执行.这使得富有表现力的高阶函数抽象如map和forEach成为可能.它也是js异步I/O方法的核心.与此同时,也可以将代码表示为字符串的形式 ...

  3. [Effective JavaScript 笔记] 第4条:原始类型优于封闭对象

    js有5种原始值类型:布尔值.数字.字符串.null和undefined. 用typeof检测一下: typeof true; //"boolean" typeof 2; //&q ...

  4. [Effective JavaScript 笔记]第3章:使用函数--个人总结

    前言 这一章把平时会用到,但不会深究的知识点,分开细化地讲解了.里面很多内容在高3等基础内容里,也有很多讲到.但由于本身书籍的篇幅较大,很容易忽视对应的小知识点.这章里的许多小提示都很有帮助,特别是在 ...

  5. [Effective JavaScript 笔记]第28条:不要信赖函数对象的toString方法

    js函数有一个非凡的特性,即将其源代码重现为字符串的能力. (function(x){ return x+1 }).toString();//"function (x){ return x+ ...

  6. JS弹出框插件zDialog再次封装

    zDialog插件网址:http://www.jq22.com/jquery-info2426 再次封装zDialog的代码: (function ($) { $.extend({ iDialog: ...

  7. easyui的window插件再次封装

    easyui的window插件再次封装 说明:该插件弹出的弹出框在最顶层的页面中,而不是在当前页面所在的iframe中,它的可拖动范围是整个浏览器窗口:所以不能用JS的parent对象获取弹出它的父页 ...

  8. ajax的再次封装!(改进版) —— new与不 new 有啥区别?

    生命不息重构不止! 上一篇写了一下我对ajax的再次封装的方法,收到了很多有价值的回复,比如有童鞋建议用$.extend,一开始还以为要做成插件呢,后来才知道,原来这个东东还可以实现合并.省着自己再去 ...

  9. ajax的再次封装!

    js的动态加载.缓存.更新以及复用 系列有点卡文,放心会继续的.先来点更基础的,为js的加载做点铺垫. jQuery的ajax本来就很方便了,为啥还要在进一步的封装呢?这个首先要看项目的具体需求了,如 ...

随机推荐

  1. Posting data to a HttpHandler greater then ~29MB gives a 404 error

    1down votefavorite 1 I am testing a HttpHandler that accepts XML. It works fine when a small amount ...

  2. 下载discuz 6 论坛的附件

    前段时间我下了个python脚本把emsky的附件全部下载了,之前是因为偶然发现emsky附件不登陆也能访问,直接访问一个url就行了. 后来发现大部分discuz6的论坛都有这个bug,我想是因为d ...

  3. 批量导出表数据到CSV文件

    需求:把oracle数据库中符合条件的N多表,导出成csv文本文件,并以表名.csv为文件名存放. 实现:通过存储过程中UTL_FILE函数来实现.导出的csv文件放入提前创建好的directory中 ...

  4. Linux - 打印文件夹全部文件 代码(C)

    列出文件夹全部文件 代码(C) 本文地址:http://blog.csdn.net/caroline_wendy 首先配置环境,參考:http://blog.csdn.net/caroline_wen ...

  5. Android - 软件自动更新的实现

    转自:http://blog.csdn.net/wwj_748/article/details/8195565 接触到一个很实用的技术,那就是软件自动更新.一般开发者是通过自行在应用平台添加更新版本的 ...

  6. Android动画的实现 上

    在Android系统中也能经常见到动画,那么如何实现动画效果呢?本文就来为大家介绍动画的实现方式. Android中动画的实现分两种方式,一种方式是补间动画Tween Animation,就是说你定义 ...

  7. iOS开发技巧系列---详解KVC(我告诉你KVC的一切)

    KVC(Key-value coding)键值编码,单看这个名字可能不太好理解.其实翻译一下就很简单了,就是指iOS的开发中,可以允许开发者通过Key名直接访问对象的属性,或者给对象的属性赋值.而不需 ...

  8. C语言结构体和联合体

    1.单链表插入 #include <stdio.h> #include <stdlib.h> #define FALSE 0 #define TRUE 1 typedef st ...

  9. HBase-再看HBase

    为什么HBase主要应用于在线应用系统?(还没搞懂) www.github.com/HBaseinaction google 三大论文  Google File System MapReduce Bi ...

  10. 几个常用myeclipse快捷键

    Ctrl + D:直接删除光标所在行 Alt + ↑:向上移动光标所在行 Alt + ↓:向下移动光标所在行 Ctrl + Alt + ↑:直接向上复制光标所在行内容 Ctrl + Alt + ↓:直 ...