Select2

Select2

koko82koko82 Posts: 12Questions: 2Answers: 0
edited August 2014 in Plug-ins

Hi,

I tried to use the plug-in called select2 but I obtained an error.
Can you told me what I wrong?
Thank you very much

(function($){

$(document).ready(function() {
    
var Editor = new $.fn.dataTable.Editor( {
        "ajax": "php/table.masterdata.php",
        "table": "#masterdata",
        "fields": [
            {
                "label": "ID",
                "name": "ID",
                "type": "text"
            },
            {
                "label": "CUSTOMER",
                "name": "CUSTOMER",
                "type": "select2",
                "ipOpts": [
                    {
                        "label": "a",
                        "value": "a"
                    },
                    {
                        "label": "b",
                        "value": "b"
                    },
                ]
            }
        ]
    } );
    
    $('#masterdata').dataTable( {
        "dom": "Tfrtip",
        "ajax": "php/table.masterdata.php",
        "columns": [
            {
                "data": "ID"
            },
            {
                "data": "CUSTOMER"
            }
        ],
        "tableTools": {
            "sRowSelect": "os",
            "aButtons": [
                { "sExtends": "editor_create", "Editor": Editor },
                { "sExtends": "editor_edit",   "Editor": Editor },
                { "sExtends": "editor_remove", "Editor": Editor }
            ]
        }
    } );

} );

}(jQuery));

This question has an accepted answers - jump to answer

Answers

  • tangerinetangerine Posts: 3,365Questions: 39Answers: 395

    .... but I obtained an error

    What error?

  • koko82koko82 Posts: 12Questions: 2Answers: 0

    ups.

    I forgot the error during the copy/paste procedure.
    I'm sorry.

    Chrome told me "Uncaught TypeError: undefined is not a function" and it highlights the row 97 of editor.select2.js

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

    The error suggests that the select2 library has not been loaded. Have you included the required Javascript and CSS files for select2?

    Allan

  • koko82koko82 Posts: 12Questions: 2Answers: 0

    Ok, I regenerated the example page with the datatable generator.
    Here you can find the HTML and the js : http://live.datatables.net/upgrade/2/edit?html,js,output or here: https://gist.github.com/anonymous/78790baa8b21d98a9899

    The browser wrote "Uncaught TypeError: Cannot read property 'create' of undefined".
    I don't know the reason.

  • allanallan Posts: 63,498Questions: 1Answers: 10,470 Site admin
    Answer ✓

    Okay great - so I see that select2 is being included. But it doesn't look like you are including the Editor select2 plug-in?

    Allan

  • koko82koko82 Posts: 12Questions: 2Answers: 0

    I do not know why the previous times did not work (I had performed the same procedure), but the important thing is that now it works.
    Thank yopu very much.

This discussion has been closed.