String clientId = table.getClientId(context);
String selectionMode = table.resolveSelectionMode();
String widgetClass = (table.getFrozenColumns() == Integer.MIN_VALUE) ? "DataTable" : "FrozenDataTable";
String initMode = table.getInitMode();
WidgetBuilder wb = getWidgetBuilder(context);
if(initMode.equals("load"))
wb.initWithDomReady(widgetClass, table.resolveWidgetVar(), clientId);
else if(initMode.equals("immediate"))
wb.init(widgetClass, table.resolveWidgetVar(), clientId);
else
throw new FacesException(initMode + " is not a valid value for initMode, possible values are \"load\" and \"immediate.");
//Pagination
if(table.isPaginator()) {
encodePaginatorConfig(context, table, wb);
}
//Selection
wb.attr("selectionMode", selectionMode, null)
.attr("rowSelectMode", table.getRowSelectMode(), "new")
.attr("nativeElements", table.isNativeElements(), false)
.attr("disabledTextSelection", table.isDisabledTextSelection(), true);
//Filtering
if(table.isFilteringEnabled()) {
wb.attr("filter", true)
.attr("filterEvent", table.getFilterEvent(), null)
.attr("filterDelay", table.getFilterDelay(), Integer.MAX_VALUE);
}
//Row expansion
if(table.getRowExpansion() != null) {
wb.attr("expansion", true).attr("rowExpandMode", table.getRowExpandMode());
}
//Scrolling
if(table.isScrollable()) {
wb.attr("scrollable", true)
.attr("liveScroll", table.isLiveScroll())
.attr("scrollStep", table.getScrollRows())
.attr("scrollLimit", table.getRowCount())
.attr("scrollWidth", table.getScrollWidth(), null)
.attr("scrollHeight", table.getScrollHeight(), null)
.attr("frozenColumns", table.getFrozenColumns(), Integer.MIN_VALUE);
}
//Resizable/Draggable Columns
wb.attr("resizableColumns", table.isResizableColumns(), false)
.attr("liveResize", table.isLiveResize(), false)
.attr("draggableColumns", table.isDraggableColumns(), false);
//Draggable Rows
wb.attr("draggableRows", table.isDraggableRows(), false);
//Editing
if(table.isEditable()) {
wb.attr("editable", true).attr("editMode", table.getEditMode()).attr("cellSeparator", table.getCellSeparator(), null);
}
//MultiColumn Sorting
if(table.isMultiSort()) {
wb.attr("multiSort", true);
}
if(table.isStickyHeader()) {
wb.attr("stickyHeader", true);
}
//Behaviors
encodeClientBehaviors(context, table);
wb.finish();
}