0
두 개의 데이터 테이블을 보여주는 응용 프로그램이 있습니다. 두 테이블 모두 버튼 확장을 사용하여 열 가시성 대화 상자를 지원합니다. 두 번째 테이블에는 제목이없는 첫 번째 열이 있습니다. 제목이 있어야 버튼을 대화 열 가시성에서, 그것은 내가 colvis 확장의 columnText 함수를 재정의 이유Javascript Assign 함수가 작동하지 않습니다.
var buttons= [{
extend: 'colvis',
postfixButtons: ['colvisRestore'],
collectionLayout: 'fixed three-column'
}];
if("secondTable" === tableName) {
buttons[0]['columnText'] = function (dt, idx, title) {
if (idx === 0) {
return "firstColumnTitle";
} else {
return title;
}
};
//add default buttons to buttons
buttons[0]['buttons'] = [{extend: 'columnsToggle'}];
//add one extra button to the collection
buttons[0]['buttons'].push([
{
extend: 'columnToggle',
text: 'HR',
columns: [1, 2]
}]);
}
DataTable({
rowId: 'id',
ajax: 'content.do',
buttons: buttons
});
내가 두 번째 테이블에만
을 촉구 columntext 기능이 기대
버튼을 추가하면 columnText
함수가 더 이상 호출되지 않습니다. 왜?
' "secondTable"=== tableName'은 절대로'true'입니까? – Adelin
조건이 true이면이 작업이 작동합니다. 'if ("secondTable"=== tableName) {...}'다음에'buttons' 변수를 콘솔에 넣고 결과를 확인할 수 있습니다. –
"secondTable"=== tablename이 참입니다. 크롬 디버거 (console.log는 동일 함)에 따르면 객체 생성시 함수를 지정하거나 나중에 값을 변경하는 것처럼 보입니다. 함수 위치 만 다른 행 번호를 나타냅니다. – tejoe