JavaScript Methods

Custom Tables includes a lightweight JavaScript API (CTEditHelper) for dynamic manipulation of records directly from the frontend or custom layouts. All methods support AJAX functionality, handle input sanitization, and integrate seamlessly with the Joomla backend.

Example Usage: #

<button onClick="SaveMe();" class="btn">Save Me</button>

JavaScript (in JavaScript Layout tab): #

function SaveMe() {
    // Save a record with ID 36
    CTEditHelper.saveRecord({ 'name': 'Ivan', 'email': 'info@ct4.us' }, 36);

    // Reload the table row with ID 36
    CTEditHelper.reloadRecord(36);
}

CTEditHelper Methods #


Create a new record. #

CTEditHelper.addRecord(fieldsAndValues, successCallback, errorCallback, url, fieldPrefix)

Parameters:

  • fieldsAndValues (object): Field-value pairs (e.g., { 'name': 'Ivan', 'email': 'info@ct4.us' })
  • successCallback (function, optional): Callback to execute on success. Receives the response data.
  • errorCallback (function, optional): Callback to execute on failure. Receives the error data.
  • url (string, optional): URL of a relevant menu item (Details/Edit Form). Defaults to the current page.
  • fieldPrefix (string, optional): Prefix for MySQL fields (es_, ct_, etc.).

Example:

CTEditHelper.addRecord({ 'name': 'Anna', 'email': 'anna@example.com' },
function(data) { console.log("Success:", data); },
function(error) { console.error("Error:", error); }
);

Save (edit) an existing record. #

CTEditHelper.saveRecord(fieldsAndValues, id, successCallback, errorCallback, url, fieldPrefix)

Parameters:

  • fieldsAndValues (object): Field-value pairs.
  • id (number): Record ID to update.
  • Remaining parameters are same as addRecord.

Example:

CTEditHelper.saveRecord({ 'status': 'active' }, 42);

Publish / Unpublish a record. #

CTEditHelper.publishRecord(id, successCallback, errorCallback, url)

CTEditHelper.unpublishRecord(id, successCallback, errorCallback, url)

Example:

CTEditHelper.publishRecord(42, function() {
alert("Record published!");
});

Refresh a record. #

CTEditHelper.refreshRecord(id, successCallback, errorCallback, url)

Example:

CTEditHelper.publishRecord(42, function() {
alert("Record published!");
});

Deletes a record. #

CTEditHelper.deleteRecord(id, successCallback, errorCallback, url)

Example:

if(confirm("Are you sure you want to delete this?")) {
CTEditHelper.deleteRecord(42, function() {
alert("Deleted!");
});
}

Duplicate a record by ID. #

CTEditHelper.copyRecord(id, successCallback, errorCallback, url)

Example:

CTEditHelper.copyRecord(42, function(newRecord) {
console.log("Copied to new ID:", newRecord.id);
});

Reload the display for a specific record (usually a table row), useful for inline updates. #

CTEditHelper.reloadRecord(id, successCallback, errorCallback, url)

Example:

CTEditHelper.reloadRecord(42);

Security & Validation #

All inputs are automatically sanitized and validated by the backend. Invalid or unauthorized operations will trigger the errorCallback with useful feedback.

Notes #

You can call these methods from Layout JavaScript tabs.

Works best with Custom Tables list views, record details pages, and inline editing layouts.

CTEditHelper object is available on every Custom Tables view or module.


What are your feelings

Leave a Reply

Updated on April 8, 2025