DataItem.inString(...), Dataset.inStrings(...) 수정

master
mjkhan21 1 year ago
parent aa32438180
commit b3ba28dba3

@ -43,12 +43,12 @@
<div class="table-responsive"> <div class="table-responsive">
<table class="datatables-ajax table table-bordered dataTable no-footer" id="DataTables_Table_0" aria-describedby="DataTables_Table_0_info"> <table class="datatables-ajax table table-bordered dataTable no-footer" id="DataTables_Table_0" aria-describedby="DataTables_Table_0_info">
<thead> <thead>
<tr><th tabindex="0" aria-controls="DataTables_Table_0" rowspan="1" colspan="1" style="width: 158.828px; text-align:center;"><input onchange="${infoPrefix}Control.select(this.checked);" type="checkbox" class="form-check-input"></th> <tr><th tabindex="0" style="width: 158.828px; text-align:center;"><input onchange="${infoPrefix}Control.select(this.checked);" type="checkbox" class="form-check-input"></th>
<th class="sorting sorting_asc" tabindex="0" aria-controls="DataTables_Table_0" rowspan="1" colspan="1" aria-sort="ascending" aria-label="Full name: activate to sort column descending" style="width: 223.719px;">계정</th> <th class="sorting sorting_asc" aria-sort="ascending" style="width: 223.719px;">계정</th>
<th class="sorting" tabindex="0" aria-controls="DataTables_Table_0" rowspan="1" colspan="1" aria-label="Email: activate to sort column ascending" style="width: 146.156px;">이름</th> <th class="sorting" style="width: 146.156px;">이름</th>
<th class="sorting" tabindex="0" aria-controls="DataTables_Table_0" rowspan="1" colspan="1" aria-label="Position: activate to sort column ascending" style="width: 195.688px;">이메일</th> <th class="sorting" style="width: 195.688px;">이메일</th>
<th class="sorting" tabindex="0" aria-controls="DataTables_Table_0" rowspan="1" colspan="1" aria-label="Office: activate to sort column ascending" style="width: 160.141px;">전화번호(무선)</th> <th class="sorting" style="width: 160.141px;">전화번호(무선)</th>
<th class="sorting" tabindex="0" aria-controls="DataTables_Table_0" rowspan="1" colspan="1" aria-label="Start date: activate to sort column ascending" style="width: 230.469px;">등록일자</th> <th class="sorting" style="width: 230.469px;">등록일자</th>
</tr> </tr>
</thead> </thead>
<tbody id="${infoPrefix}List"> <tbody id="${infoPrefix}List">
@ -56,11 +56,11 @@
<template id="${infoPrefix}Row"> <template id="${infoPrefix}Row">
<tr data-key="{USER_ID}"> <tr data-key="{USER_ID}">
<td style="text-align:center;"><input value="{USER_ID}" onchange="${infoPrefix}Control.select('{USER_ID}', this.checked);" type="checkbox" class="form-check-input"></td> <td style="text-align:center;"><input value="{USER_ID}" onchange="${infoPrefix}Control.select('{USER_ID}', this.checked);" type="checkbox" class="form-check-input"></td>
<td onclick="${infoPrefix}Control.setCurrent('{USER_ID}')" ondblclick="${infoPrefix}Control.getInfo({})">{USER_ACNT}</td> <td {onclick} {ondblclick}>{USER_ACNT}</td>
<td onclick="${infoPrefix}Control.setCurrent('{USER_ID}')" ondblclick="${infoPrefix}Control.getInfo({})">{USER_NM}</td> <td {onclick} {ondblclick}>{USER_NM}</td>
<td onclick="${infoPrefix}Control.setCurrent('{USER_ID}')" ondblclick="${infoPrefix}Control.getInfo({})">{EML_ADRS}</td> <td {onclick} {ondblclick}>{EML_ADRS}</td>
<td onclick="${infoPrefix}Control.setCurrent('{USER_ID}')" ondblclick="${infoPrefix}Control.getInfo({})">{MBL_TELNO}</td> <td {onclick} {ondblclick}>{MBL_TELNO}</td>
<td onclick="${infoPrefix}Control.setCurrent('{USER_ID}')" ondblclick="${infoPrefix}Control.getInfo({})">{REG_DT}</td> <td {onclick} {ondblclick}>{REG_DT}</td>
</tr> </tr>
</template> </template>
<template id="${infoPrefix}NotFound"> <template id="${infoPrefix}NotFound">
@ -125,8 +125,21 @@ function render${infoPrefix}List() {
let empty = ${infoPrefix}List.empty; let empty = ${infoPrefix}List.empty;
let trs = empty ? let trs = empty ?
[document.getElementById("${infoPrefix}NotFound").innerHTML] : <%-- from template#${infoPrefix}NotFound --%> [document.getElementById("${infoPrefix}NotFound").innerHTML] : <%-- from template#${infoPrefix}NotFound --%>
${infoPrefix}List.inStrings(document.getElementById("${infoPrefix}Row").innerHTML); <%-- from template#${infoPrefix}Row --%> ${infoPrefix}List.inStrings(
document.getElementById("${infoPrefix}Row").innerHTML, <%-- from template#${infoPrefix}Row --%>
(str, dataItem) => str
.replace(/{onclick}=""/gi, 'onclick="userControl.setCurrent(\'' + dataItem.getValue("USER_ID") + '\');"')
.replace(/{ondblclick}=""/gi, 'ondblclick="userControl.getInfo(\'' + dataItem.getValue("USER_ID") + '\')"')
<%-- OR
(str, dataItem) => {
let userID = dataItem.getValue("USER_ID");
return str
.replace(/{onclick}=""/gi, 'onclick="userControl.setCurrent(\'' + userID + '\');"')
.replace(/{ondblclick}=""/gi, 'ondblclick="userControl.getInfo(\'' + userID + '\')"')
}
--%>
);
$("#${infoPrefix}List").html(trs.join()); $("#${infoPrefix}List").html(trs.join());
$("th input[type='checkbox']").prop("checked", false); $("th input[type='checkbox']").prop("checked", false);
} }

@ -273,10 +273,14 @@ class DataItem {
/**Returns a string converted from the template using the property values of the user data. /**Returns a string converted from the template using the property values of the user data.
* In the template, placeholder for the properties of the user data is specified like {property name}. * In the template, placeholder for the properties of the user data is specified like {property name}.
* @param {string} template template string * @param {string} template template string
* @param {function} formatter function to format a row string with custom property placeholders
* @returns {string} string converted from the template using the property values of the user data * @returns {string} string converted from the template using the property values of the user data
*/ */
inString(template) { inString(template, formatter) {
let str = template; let str = template;
if (formatter) {
str = formatter(str, this);
}
for (let p in this.data) { for (let p in this.data) {
let regexp = this._formats.regexp(p); let regexp = this._formats.regexp(p);
str = str.replace(regexp, this.getValue(p)); str = str.replace(regexp, this.getValue(p));
@ -1087,11 +1091,12 @@ class Dataset {
/**Returns an array of strings converted from the template using the property values of the Dataset's user data. /**Returns an array of strings converted from the template using the property values of the Dataset's user data.
* In the template, placeholder for the properties of the user data is specified like {property name}. * In the template, placeholder for the properties of the user data is specified like {property name}.
* @param {string} template template string * @param {string} template template string
* @param {function} formatter function to format a row string with custom property placeholders
* @returns {array} array of strings converted from the template using the property values of the user data * @returns {array} array of strings converted from the template using the property values of the user data
*/ */
inStrings(template) { inStrings(template, formatter) {
return this.getDataset("item") return this.getDataset("item")
.map(item => item.inString(template)); .map(item => item.inString(template, formatter));
} }
/**Returns a property value of user data. /**Returns a property value of user data.

Loading…
Cancel
Save