jquery dynamically displays and hides a column in the DataGrid _jquery

Source: Internet
Author: User
Copy Code code as follows:

$ (function () {
$ (' #tt '). DataGrid ({
Title: ' Report Statistics ',
width:1020,
height:400,
URL: ',
Fitcolumns:true,
Loadmsg: ' Getting, please wait ... ',
Singleselect:true,
Nowrap:false,
columns:[[
{field: ' Region_name ', title: ' Branch ', width:30,align: ' Center '},
{field: ' County_name ', title: ' Counties ', width:80,align: ' Center ', editor: ' Text '},
{field: ' Area_name ', title: ' Grid ', Width:80,align: ' Center ', editor: ' Text '},
{field: ' Org_name ', title: ' Dot ', width:80,align: ' Center '},
{field: ' Total_num ', Title: ' Total volume of business ', Width:40,align: ' Center '},
{field: ' Dh_num ', title: ' Single breadth of traffic ', Width:40,align: ' Center '},
{field: ' Rh_num ', title: ' Fusion Traffic ', Width:40,align: ' Center '},
{field: ' Yyt_num ', Title: ' Business Volume ', width:40,align: ' Center '},
{field: ' Qt_num ', title: ' Other business volume ', width:40,align: ' Center '}
]],
toolbar:[
],
Ondblclickrow:function () {
Selected = $ (' #tt '). DataGrid (' getselected ');
var index = $ (' #tt '). DataGrid (' Getrowindex ', selected);
$ (' #tt '). DataGrid (' BeginEdit ', index);
Progress ();
Taskpreempte (Selected.taskid);
}
});

$ (' #my_toolbar '). Appendto ('. Datagrid-toolbar ');

var dd = new Date ();
var D1 = dd.getfullyear () + "-" + (Dd.getmonth () +1) + "-1";
var d2 = dd.getfullyear () + "-" + (Dd.getmonth () +1) + "-" + dd.getdate ();
$ (' #qryStartDate '). Datebox (' SetValue ', D1); Set Datebox value
$ (' #qryEndDate '). Datebox (' SetValue ', D2); Set Datebox value
RefreshRpt2 ();

});

function RefreshRpt2 () {
var strstatcond = "B.region_name";
if ($ (' #qryCon '). attr ("value")!=100) {
param.sts = $ (' #qryCon '). attr ("value");
alert (param.sts);
}
Param.qrybegintime =$ (' #qryStartDate '). Datebox (' GetValue ');
alert (param.qrybegintime);
Param.qryendtime = $ (' #qryEndDate '). Datebox (' GetValue ');
alert (param.qryendtime);

if ($ (' #region ')!= null && $ (' #region '). attr ("checked") = = True) {

}
if ($ (' #county ')!= null && $ (' #county '). attr ("checked") = = True) {
Strstatcond + = ", c.county_name";
$ (' #tt '). DataGrid (' Showcolumn ', ' county_name ');

}else{
$ (' #tt '). DataGrid (' Hidecolumn ', ' county_name ');
}

if ($ (' #area ')!= null && $ (' #area '). attr ("checked") = = True) {
Strstatcond + = ", d.area_name";
$ (' #tt '). DataGrid (' Showcolumn ', ' area_name ');
}else{
$ (' #tt '). DataGrid (' Hidecolumn ', ' area_name ');
}
if ($ (' #org ')!= null && $ (' #org '). attr ("checked") = = True) {
Strstatcond + = ", e.org_name";
$ (' #tt '). DataGrid (' Showcolumn ', ' org_name ');
}else{
$ (' #tt '). DataGrid (' Hidecolumn ', ' org_name ');
}
alert (Strstatcond);
Param.statcond = Strstatcond;
Param.rptname = "Statbusirpt";
Jsbasecall.execute (PARAM,SHOWRESULT2);
}
Show recordset
function ShowResult2 (data) {
var strjson=data["defaultjsonstring"];
var result=eval (' + Strjson + ');
alert (Strjson);
if (result. Key_jscall_result) {
if (result. Key_service_res) {//success
Totalrec=result. Key_total_rec;
var d={"Total":p Ageshowrec,
"Rows": result.defaultalist
};
$ (' #tt '). DataGrid (' LoadData ', d);
}
}
}

For example, in the "Qu County" when there is no data, the table does not show empty columns, but directly to hide this column

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.