-1

On my DataTable Jquery, I need to initialize (Using JS / JQuery) manually, the data-plugin = "selectable" plugin. When I add it to the html, everything works correctly, but I need to initialize it manually, using Jquery. Does anyone know how to help me?

Tank you!

<div class="panel panel-default">
    <table id="dtFinanceiroParcela" class="table table-striped table-bordered center-header table-vcenter table-responsive-lg" data-plugin="selectable" data-row-selectable="true" cellspacing="0" width="100%">
        <thead class="bg-blue-grey-100">
            <tr>
                <th>
                    <span class="checkbox-custom checkbox-default">
                        <input class="selectable-all" type="checkbox">
                        <label></label>
                    </span>
                </th>
                <th>
                    Parcela
                </th>
                <th>
                    Data de Emissão
                </th>
                <th>
                    Data de Vencimento
                </th>
                <th>
                    Valor da Parcela
                </th>
                <th>
                    Situação
                </th>
                <th>
                    Ações
                </th>
            </tr>
        </thead>
        <tbody></tbody>
    </table>
</div>

I tried to do it like this, but it didn't work:

$('#dtFinanceiroParcela').selectable();
Master JR
  • 231
  • 2
  • 11
  • I may have misunderstood the question - but are you looking for the [`select: true`](https://datatables.net/extensions/select/#Initialisation) option? This assumes you have already included the required "select" CSS and JS in your page (from [here](https://datatables.net/download/)). – andrewJames Nov 21 '20 at 23:11
  • Or, are you looking for a way to load those CSS and JS files dynamically? In which case, does something like [this](https://stackoverflow.com/questions/2685614/load-external-css-file-like-scripts-in-jquery-which-is-compatible-in-ie-also) help? – andrewJames Nov 21 '20 at 23:11
  • It would not be referencing CSS or JS. It would be to initialize the plugin, because I'm using ASP.NET core mvc and in my form, I'm setting the Layout to null. – Master JR Nov 22 '20 at 00:05
  • OK - thank you. I am not sure what you mean by "initialize the plugin", in that case. Perhaps this would mean something to a ASP.NET user. Maybe you should add that tag to your question? – andrewJames Nov 22 '20 at 01:04

1 Answers1

1

I hope that this solution can help other people who have the same problem... After an exhaustive search on the web, I found the solution to start the plugin:

var defaults = Plugin.getDefaults('selectable');
var Switcher = Plugin.getPlugin('selectable');

var dtFinanceiroParcela = $('#dtFinanceiroParcela');
var plugin = new Switcher(dtFinanceiroParcela, defaults);
plugin.initialize(); 
Master JR
  • 231
  • 2
  • 11