Page 1 of 1
Conditional use of Custom Template
Posted: Wed Jan 10, 2018 7:24 pm
by sangnandar
This code,
View Page, Client Scripts:
$(document).on("rendertemplate", function(e, args) {
if (args.template) {
if (args.id == "tpd_<tablename>") { // with or without this check
args.enabled = false;
ew_ShowTemplates(args.template.substr(4));
}
}
});
Didn't work, threw the error:
Uncaught TypeError: Cannot read property 'substr' of undefined
console.log(args.template.substr(4)); // output: (mytablename)view
Re: Conditional use of Custom Template
Posted: Thu Jan 11, 2018 10:51 am
by Webmaster
- If (args.template) is defined, args.template.substr(4) will not possibly cause "cannot read property 'substr' of undefined". You probably have another old handler you forgot to remove, double check HTML in your browser and look for "rendertemplate". However, note that "tpd<tablename>" should be "tpd<tablename>view" for View page, view HTML source in browser to check the id.
- In v2018, the CSS class "hidden" is used to hide the original table, you also need to remove the class after calling ew_ShowTemplates(), view HTML source in browser to check the class name.
Re: Conditional use of Custom Template
Posted: Thu Jan 11, 2018 1:08 pm
by sangnandar
What's the point of calling ew_ShowTemplates() (that is to show), but yet again has to remove the class manually (in order to show)? I assumed that it should (logically) has been done within ew_ShowTemplates() so I didn't check the class.
I found another problem applying the scenario on List Page.
The ListOption items didn't drawn properly, always drawn on the left, both at table head and body (didn't check footer).
This is my working code to fix the problem in case else need it.
$(document).on("rendertemplate", function(e, args) {
if (ewVar.userlevel == -1) { // the condition
if (args.template) {
args.enabled = false;
var tablename = args.template.substr(4);
ew_ShowTemplates(tablename);
$("#tbl" + tablename).removeClass("hidden");
// fix header
var that = $("#tbl" + tablename + ">thead>tr");
$("#tbl" + tablename + ">thead>tr").find(".ewListOptionHeader").each(function(){
$(this).detach().appendTo(that);
});
that.children("span." + tablename).remove();
// fix body
$("#tbl" + tablename + ">tbody>tr").each(function(){
var those = $(this);
$(this).find(".ewListOptionBody").each(function(){
$(this).detach().appendTo(those);
});
});
}
}
});
Adjust .appendTo() method to .prependTo() if you do link on the left side.