Standalone fields - cannot get initial values to load and cannot save new values

Standalone fields - cannot get initial values to load and cannot save new values

MarkAndersonUKMarkAndersonUK Posts: 39Questions: 14Answers: 0


I am trying hard to get the Standalone edit mode to work in my site, but am not getting very far. I hope someone who is more knowledgeable than I (this is not hard as I am a total novice) can help (@allan if you have time?) , or send me an example that I can work from to correct my mistakes.

The basic setup is I have a table that is used to store contacts (called 'recruits'), then I have a table that stores data about these contacts (called 'recruits_data'). Ideally, I want to show the 'recruits table in a datagrid, then when one row is selected, I want the standalone fields to populate with data from the 'recruits_data' table. I previously had this working flawlessly when using two datagrids (one for each table), but design requirements make using Standalone fields a much better fit for the application.

I am using Node.JS and the data is stored in mySQL.

The problems I am seeing are ;

  1. The data from the 'recruits_data' table does not populate the initial standalone fields. I have tried using both the INLINE and EDIT options.

  2. When saving a field, everything appears to work (no errors) but the data is not saved. I notice that the AJAX url is called correctly and the data appears correct, but the response looks like nothing occurred. See the data example below:

**Request: **

data[1][recruits_data][status]: New Recruit
action: edit
recruitID: 1

**Response : **

Here is my setup (note I use Jade/Pug, so the HTML will look a little strange, but it is fairly
easy to follow if you ignore the strangeness of the look.)

**HTML / Pug File **

extends layout

block content
    #datamain.container-fluid(style='margin-top: 20px;)
                    table#recruits.display.compact(cellpadding='0' cellspacing='0' border='0' width='100%')
                                th.small Recruit ID
                                th.small NPN ID
                                th.small First
                                th.small Middle
                                th.small Last
                            dt recruitID:
                            dt Status:
                                button#rd_data_edit Edit

block append footer

(function ($) {
    $(document).ready(function () {

        // *** START Recruits Editor ***
        var recruitEditor = new $.fn.dataTable.Editor({
            ajax: '/demo/api/recruits',
            table: '#recruits',
            fields: [
                {label: "Recruit ID:", name: "recruits.recruitID",type:  "readonly"},
                {label: "NPN ID:", name: "recruits.NPN"},
                {label: "First Name:", name: "recruits.FirstName"},
                {label: "Middle Name:", name: "recruits.MiddleName"},
                {label: "Last Name:", name: "recruits.LastName"}

        var recruit_table = $('#recruits').DataTable({
            dom: 'Blfrtip',
            ajax: {
                url: '/demo/api/recruits',type: "POST"},
            serverSide: true,
            processing: false,
            columns: [
                {data: "recruits.recruitID", class: "small dt-body-center", visible: false},
                {data: "recruits.NPN", class: "small dt-body-center", visible: false},
                {data: "recruits.FirstName", class: "small",searchable: false},
                {data: "recruits.MiddleName", class: "small",searchable: false},
                {data: "recruits.LastName", class: "small",searchable: false}
        // *** END Recruits Editor ***

        // *** START Data Editor ***
        var r_dataEditor = new $.fn.dataTable.Editor({
            ajax: {
                url: '/demo/api/recruits_data',
                async: true,
                data: function (d) {
                    var selected = recruit_table.row({selected: true});
                    if (selected.any()) {
                        d.recruitID =;
            fields: [
                {label: "recruitID:", name: "recruits_data.recruitID", type: "readonly"},
                {label: "Status:",name: "recruits_data.status",type: "select",placeholder: "Select the Status",options: ["New Recruit", "Not Contacted", "Contacted", "Callback", "Meeting Set", "No Show", "Agent Info Sent", "Agent Info Completed", "Contract", "Compass Agent", "Lost - Not Interested", "Lost - Not a Candidate", "Lost - Remove from Marketing"]}

        $('[data-editor-field]').on( 'click', function (e) {
                .inline( this, {
                    buttons: '_basic'
                } );
        } );

        $('#rd_data_edit').on( 'click', function () {
                .buttons( {
                    label: "Save",
                    fn: function () { this.submit(); }
                } )
        } );

        // *** END Data Editor ***

        recruit_table.on('select', function (e) {
            $("#rd_data_div").attr("data-editor-id",recruit_table.row({selected: true}).data().recruits.recruitID);

                .def(recruit_table.row({selected: true}).data().recruitID);

        r_dataEditor.on('submitSuccess', function () {

Controller / Node.JS Route File

const router = require('express').Router();
const expressValidator = require('express-validator');
const middleware = require('./middleware.js');

let myDB = require('../recruiting');
let {
} = require("");

//All routes from /LifeCases are routed here.
router.get("/", middleware.loggedIn(), (req,res) => {
    res.render('demo', {showAdmin: true})

router.all('/api/recruits', async function(req, res) {
    let editor = new Editor(myDB, 'recruits', 'recruits.recruitID')
            new Field("recruits.recruitID")
                .setFormatter( Format.ifEmpty(null)),
            new Field("recruits.NPN")
                .setFormatter( Format.ifEmpty(null)),
            new Field("recruits.FirstName")
                .setFormatter( Format.ifEmpty( null )),
            new Field("recruits.MiddleName")
                .setFormatter( Format.ifEmpty( null )),
            new Field("recruits.LastName")
                .setFormatter( Format.ifEmpty( null ))

    await editor.process(req.body);

router.all('/api/recruits_data', async function(req, res) {
    if (! req.body.recruitID) {

    let editor = new Editor(myDB, 'recruits_data', 'recruits_data.recruitID')
            new Field("recruits_data.recruitID")
                .setFormatter( Format.ifEmpty(null)),
            new Field("recruits_data.status")
                .setFormatter( Format.ifEmpty( 'New Recruit' )),

        .where( function () {
            this.where( 'recruits_data.recruitID', req.body.recruitID );
        } )

    await editor.process(req.body);


module.exports = router;

Any Help, advice, or examples would be gratefully received. I does appear that using StandAlone would be perfect for my application, so I do hope someone can point me in the correct direction here.

thanks you so much,


  • rf1234rf1234 Posts: 2,368Questions: 76Answers: 341

    I didn't look at your code but I can share my experience. I never got standalone editing to work with Editor. My workaround is that I use Editor with invisible data tables that have one column and mostly just one row. Then everything works as usual even though it is a bit annoying to have that pseudo-data table stuff in the code.

  • MarkAndersonUKMarkAndersonUK Posts: 39Questions: 14Answers: 0

    Thanks @rf1234

    That is funny, I was just starting to do that here. As if I create a table
    with a single field, and then hide the header, make it not sortable, it looks just like a standalone field and works perfectly. It's a shame to do it that way, but it will work.

    thanks for your comment.

Sign In or Register to comment.