如何在jtable中使用jquery Select2

vi4fp9gy  于 2023-08-04  发布在  jQuery
关注(0)|答案(3)|浏览(143)

我只是在mvc应用程序中使用jQuery jtable,并使用级联下拉列表,我想在下拉列表中使用select2,我如何使用它?

dpiehjr4

dpiehjr41#

我没有使用jTable,但我认为可以在加载时使用jtalbe回调函数。

$('.your-table').jtable('load', undefined, function(){
  $('.your-table').find('select').select2();
});

字符串

3df52oht

3df52oht2#

我会将select2更改放在recordsLoaded回调函数中,而不是load方法回调函数中。将其放置在那里,代码将在load、reload、addRecord和updateRecord时被调用。

4zcjmb1e

4zcjmb1e3#

如何使select 2在create jtable模式下工作。我有选择2在模态的时刻,但我不能写搜索...
外部纳税人:{ title:'test',create:true,编辑:false,list:true,//设置为true,启用列表视图listClass中的列:'select2-init',inputClass:'select 2-init',选项:{ 1:“Avalara”,0:“Nenhum”},//在列中添加一个CSS类,display:function(data){ var html =““;

html += "</select></div>";
                        return html;
                    },
                    input: function (data) {
                        if (data.formType === 'create') {
                            var html = "<div class=\"span3\"> <select id=\"subProductsListDDL\" name=\"ExternalTaxProvider\">";;
                            // Add options or logic for create form here
                            // For example: You can add option elements inside the select element
                          
                            return html;
                        } else {
                            // Add options or logic for edit form here
                            // Example: You can get the current value with data.value
                            return data.record.ExternalTaxProvider;
                        }

                    }
                },
            },
            formCreated: function (event, data) {
                // Initialize the Select2 input for the "ExternalTaxProvider" field in the create/edit form
                if (data.formType === 'create' || data.formType === 'edit') {
                    
                    // Find the existing input element for "ExternalTaxProvider"
                    var $originalInput = data.form.find('[name="ExternalTaxProvider"]');
                    // Replace the original input with the $input (Select2-enhanced) element

                    initSelect2ForExternalTaxProvider();
                    // Initialize the Select2 for the "ExternalTaxProvider" field
                    $originalInput.select2({
                        placeholder: 'Test',
                        minimumInputLength: 1,
                         data: [
                { id: 1, text: 'Option 1' },
                { id: 2, text: 'Option 2' },
                { id: 3, text: 'Option 3' },
                // Add more options as needed
            ]
                    });
                }
            },

        });
This is what I have! the data is just for testing because o not know what is the problem...
thank you :)

字符串

相关问题