Extend select options, feature suggestions

Extend select options, feature suggestions

rldean1rldean1 Posts: 141Questions: 66Answers: 1

@allan @kthorngren @colin

Hello, I would like to suggest a couple of features for consideration for the select plugin. I think it might be beneficial for other developers (and selfishly, me as well). Some of these things may overlap. I hope I don't sound stupid:

  1. an option to prevent re-select after ajax.reload();, based on some sort of evaluation or condition that the developer makes
  2. "extending" the select plugin to control other jQuery Tabs, Buttons, or other elements OUTSIDE of DataTables (Example: If there is a selection, disable a specific jQuery Tabs)
  3. ability to get historical selections, or get the last known selection, to evaluate it against the current selection
  4. "extending" the select plugin so that it can see and evaluate all selections, across all tables, to allow the developer to further evaluate the selections, to manipulate navigation options.
  5. a centrally controlled selection handler plug-in, that can evaluate selections across all tables (rather than separately controlled select even handlers per table)
  6. the ability to retain information about previous selections AFTER Editor CRUD events

Why do I have these ideas?

  1. I have 5 DataTables, 5 Editors, and 5 jQuery tabs, each Tab has a Table
  2. NAVIGATION: it works from left-to-right, like a tree: Branches of a tree, where stuff on the left drives your ability to move to the right.
  3. row clicks, via the select event, define the selections, and then ultimately disable/enable Tabs
  4. Tab clicks ALSO get the selected row data, BUT, they define the server request, and call ajax.reload() the table
  5. My issues is moving right-to-left. I don't want to disable all the tabs to the right, if some of the selected data is the same.

Here, I'll share some code with you. It's a selection handler I've built, but the part that controls the jQuery tabs is not working perfectly. Maybe it'll give you some ideas.

    , selectionHandler: {
        selectObj: {
            EffectDate: '',
            Schedule: '',
            CD: '',
            DSH: '',
            CDCode: '',
            Grade: '',
            Step: ''
        },
        setFromTable: function (table) {

            rowData = table.row('.selected').data();
            $.each(this.selectObj, function (key, val) {
                salary.selectionHandler.selectObj[key] = rowData[key]
            });

            return this;
        },
        rediscoverSelections: function () {
            /**
             * 
             * Loop through tabs starting at Index 0
             * up to the currently selected tab;
             * If the table has a row selected, get {rowData},
             * and update {selectObj}.
             * 
             */

            tabIndex = $("#tabs").tabs('option', 'active');  // index for Active Tab
            tableAry = [tblEffectiveDates, tblSchedules, tblScalesHourly, tblAnnualContracts, tblAnnualScales];
            rowData = {};

            for (i = 0; i <= tabIndex; i++) {
                if (tableAry[i].row('.selected').any()) {
                    rowData = tableAry[i].row('.selected').data();
                };
            };

            if (rowData == undefined) {
                // nothing selected, clear all values
                $.each(this.selectObj, function (key, val) {
                    salary.selectionHandler.selectObj[key] = '';
                });
            } else {
                $.each(this.selectObj, function (key, val) {
                    salary.selectionHandler.selectObj[key] = rowData[key];
                });
            };

            return this;

        },
        setFromRowData: function (data) {

            if (typeof data !== 'object') {
                return this;
            } else {
                $.each(this.selectObj, function (key, val) {
                    salary.selectionHandler.selectObj[key] = data[key]
                });
            };

            return this;

        },
        getObject: function () {
            return this.selectObj;
        },
        setTabs: function () {


            if (this.selectObj.EffectDate && !this.selectObj.Schedule && !this.selectObj.Grade && !this.selectObj.Step && !this.selectObj.CD && !this.selectObj.DSH && !this.selectObj.CDCode) {
                $("#tabs").tabs("option", "disabled", [2, 3, 4]);
            };

            if (this.selectObj.EffectDate && this.selectObj.Schedule && !this.selectObj.Grade && !this.selectObj.Step && !this.selectObj.CD && !this.selectObj.DSH && !this.selectObj.CDCode) {
                $("#tabs").tabs("option", "disabled", [4]);
            };

            if (this.selectObj.EffectDate && this.selectObj.Schedule && this.selectObj.Grade && this.selectObj.Step && !this.selectObj.CD && !this.selectObj.DSH && !this.selectObj.CDCode) {
                tblAnnualContracts.row('.selected').deselect();
                $("#tabs").tabs("option", "disabled", [4]);
            };

            if (this.selectObj.EffectDate && this.selectObj.Schedule && !this.selectObj.Grade && !this.selectObj.Step && this.selectObj.CD && this.selectObj.DSH && this.selectObj.CDCode) {
                $("#tabs").tabs("option", "disabled", []);
            };

            if (this.selectObj.EffectDate && this.selectObj.Schedule && this.selectObj.Grade && this.selectObj.Step && this.selectObj.CD && this.selectObj.DSH && this.selectObj.CDCode) {
                $("#tabs").tabs("option", "disabled", []);
            };

            if (!this.selectObj.EffectDate && !this.selectObj.Schedule && !this.selectObj.Grade && !this.selectObj.Step && !this.selectObj.CD && !this.selectObj.DSH && !this.selectObj.CDCode) {
                $("#tabs").tabs("option", "disabled", [1, 2, 3, 4]);
            };

            return this;

        },
        defineJSONrequest: function () {
            $("#jsonRequest").val(JSON.stringify(this.selectObj));
        }
    }

Replies

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin

    Hi,

    Thanks for the suggestions! It's worth quickly staying that you don't need to tag us - and also that Kevin is a volunteer in the forum (and damn does he do fine work). It is Colin, Sandy and myself on the payroll.

    an option to prevent re-select after ajax.reload();, based on some sort of evaluation or condition that the developer makes

    As a workaround you could deselect the rows immediately after the reload:

    table.ajax.reload( function () {
      table.rows().deselect();
    } );
    

    "extending" the select plugin to control other jQuery Tabs, Buttons, or other elements OUTSIDE of DataTables (Example: If there is a selection, disable a specific jQuery Tabs)

    For that the select and deselect exist, so you can control other elements based on the selection state of the table. It would be impossible for us to attempt to control other libraries from inside Select.

    ability to get historical selections, or get the last known selection, to evaluate it against the current selection

    It's an interesting idea. Probably not something we'll put in at the moment, since this is the first request for that feature, but if others request it as well, we can look into it (it's not something we've needed ourselves for example). Until then, you could use table.rows({selected:true}).indexes() to get the current state and save that into a variable. You'd probably need to trigger that action from a button so the user knows what they are comparing to what.

    "extending" the select plugin so that it can see and evaluate all selections, across all tables, to allow the developer to further evaluate the selections, to manipulate navigation options.

    The API is already multi-table aware. I've put this trivial example together to show that: http://live.datatables.net/kukejexi/1/edit

    a centrally controlled selection handler plug-in, that can evaluate selections across all tables (rather than separately controlled select even handlers per table)

    You can also do this already as the select and deselect events bubble to the top. So if you listen for them at the document level all DataTable selection events will appear there, regardless of the source table.

    Here is an example showing that: http://live.datatables.net/luhavase/1/edit .

    the ability to retain information about previous selections AFTER Editor CRUD events

    That should already be happening - see: https://editor.datatables.net/examples/simple/simple.html .

    Allan

This discussion has been closed.