Skip to content

Commit

Permalink
JQMDataTable minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
slavap committed Nov 15, 2016
1 parent 4e42200 commit ee781ac
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 10 deletions.
Expand Up @@ -311,13 +311,14 @@ public void onClick(ClickEvent event) {
JsArrayMixed r = createDataRow(i);
dataTable3.addRow(r);
}
dataTable3.rowsInvalidate(true);
dataTable3.refreshDraw(true);
}
});
btnDeleteSelRow.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
dataTable3.removeSelRows();
dataTable3.refreshPage();
}
});

Expand Down
Expand Up @@ -1132,11 +1132,26 @@ public void ajaxReload(String newUrl, boolean resetPaging) {
/**
* Softer than {@link JQMDataTable#ajaxReload(boolean) }, uses already loaded client side data.
* <br> In case of (serverSide == true) it's practically the same as ajaxReload().
*
* @param resetPaging - if <b>true(full-reset)</b> then the ordering and search will be recalculated
* and the rows redrawn in their new positions. The paging will be reset back to the first page.
* <br> if <b>false(full-hold)</b> then the ordering and search will be recalculated
* and the rows redrawn in their new positions. The paging will not be reset - i.e. the current
* page will still be shown.
**/
public void refreshDraw(boolean resetPaging) {
JsDataTable.draw(getElement(), resetPaging);
}

/**
* The ordering and search will not be updated and the paging position held where is was.
* This is useful for paging when data has not been changed between draws.
* <br> See <a href="https://datatables.net/reference/api/draw()">draw()</a> documentation.
*/
public void refreshPage() {
JsDataTable.drawPage(getElement());
}

public String getDataSrc() {
return dataSrc;
}
Expand Down Expand Up @@ -1399,28 +1414,60 @@ public void clearData() {
JsDataTable.clearData(getElement());
}

/**
* Allows multiple additions, like addRow(); addRow(); ...; refreshDraw();
* <br> refreshDraw() or refreshPage() must be called after it to repaint dataTable.
*/
public void addRow(JavaScriptObject newRow) {
JsDataTable.addRow(getElement(), newRow);
}

/**
* Allows multiple removals, like removeRow(); removeRow(); ...; refreshDraw();
* <br> refreshDraw() or refreshPage() must be called after it to repaint dataTable.
*/
public void removeRow(int rowIndex) {
JsDataTable.removeRow(getElement(), rowIndex);
}

public void removeSelRows() {
/**
* refreshDraw() or refreshPage() must be called after it to repaint dataTable.
*/
public boolean removeSelRows() {
JsArrayInteger sel = JsDataTable.getSelRowIndexes(getElement());
if (sel.length() == 0) return;
if (sel.length() == 0) return false;
int[] idxs = new int[sel.length()];
for (int i = 0; i < idxs.length; i++) idxs[i] = sel.get(i);
Arrays.sort(idxs);
for (int i = idxs.length - 1; i >= 0; i--) {
removeRow(idxs[i]);
}
rowsInvalidate(true);
return true;
}

public void rowsInvalidate(boolean resetPaging) {
JsDataTable.rowsInvalidate(getElement(), resetPaging);
/** Invalidate all rows. refreshDraw() or refreshPage() must be called after it to repaint dataTable. */
public void rowsInvalidate() {
JsDataTable.rowsInvalidate(getElement());
}

/** Just a synonym for rowsInvalidate() */
public void invalidateRows() {
rowsInvalidate();
}

public void invalidateRow(int rowIndex) {
JsDataTable.invalidateRow(getElement(), rowIndex);
}

/** @param cellOrRowElt - could be cellElt or rowElt */
public void invalidateRow(Element cellOrRowElt) {
JsDataTable.invalidateRow(getElement(), cellOrRowElt);
}

/** @param cellElt - cell or one of its children
*/
public void invalidateCell(Element cellElt) {
JsDataTable.invalidateCell(getElement(), cellElt);
}

public RowIdHelper getRowIdHelper() {
Expand Down
Expand Up @@ -898,9 +898,13 @@ static native void draw(Element elt, boolean resetPaging) /*-{
$wnd.$(elt).DataTable().draw(resetPaging);
}-*/;

/** Invalidate all rows and redraw, useful after data changes, see addRow() */
static native void rowsInvalidate(Element elt, boolean resetPaging) /*-{
$wnd.$(elt).DataTable().rows().invalidate().draw(resetPaging);
static native void drawPage(Element elt) /*-{
$wnd.$(elt).DataTable().draw('page');
}-*/;

/** Invalidate all rows. draw() or drawPage() must be called after it to repaint dataTable. */
static native void rowsInvalidate(Element elt) /*-{
$wnd.$(elt).DataTable().rows().invalidate();
}-*/;

static native JavaScriptObject getData(Element elt) /*-{
Expand All @@ -918,14 +922,42 @@ static native void destroy(Element elt) /*-{
$wnd.$(elt).DataTable().destroy();
}-*/;

/**
* Allows multiple additions, like addRow(); addRow(); ...; draw();
* <br> draw() or drawPage() must be called after it to repaint dataTable.
*/
static native void addRow(Element elt, JavaScriptObject newRow) /*-{
$wnd.$(elt).DataTable().row.add(newRow);
}-*/;

/**
* Allows multiple removals, like removeRow(); removeRow(); ...; draw();
* <br> draw() or drawPage() must be called after it to repaint dataTable.
*/
static native void removeRow(Element elt, int rowIndex) /*-{
$wnd.$(elt).DataTable().row(rowIndex).remove();
}-*/;

static native void invalidateRow(Element tableElt, int rowIndex) /*-{
$wnd.$(elt).DataTable().row(rowIndex).invalidate();
}-*/;

static native void invalidateRow(Element tableElt, Element cellElt) /*-{
var tr = $wnd.$(cellElt).closest('tr');
var r = $wnd.$(tableElt).DataTable().row(tr);
r.invalidate();
}-*/;

static native void invalidateCell(Element tableElt, Element cellElt) /*-{
var $cell = $wnd.$(cellElt);
var cellSel = $cell.closest('td');
if (cellSel.length === 0) cellSel = $cell.closest('th');
if (cellSel.length !== 0) {
var cell = $wnd.$(tableElt).DataTable().cell(cellSel);
cell.invalidate();
}
}-*/;

public static native Element findTableElt(Element tableChildElt) /*-{
var t = $wnd.$(tableChildElt).closest('table');
return t ? t[0] : null;
Expand Down Expand Up @@ -966,7 +998,7 @@ static native void addCellClickHandler(Element elt, String cellWidget,
var rowData = null, rowIdx = -1;
if (row) {
if (row.data()) rowData = row.data();
if (row.index()) rowIdx = row.index();
rowIdx = row.index();
}
if (rowColRequired && (rowIdx === -1 || colIdx === -1)) {
// probably row details widget was clicked
Expand Down

0 comments on commit ee781ac

Please sign in to comment.