I'm using jquery autocomplete and it's working fine but I want to use bootstrap <table> in the dropdown list
it worked fine in display but I cannot use <li></li> in <tbody></tbody> so I couldn't get the selected value
the following is the code
- <div class="col-4">
- <div class="input-group">
- <span class="input-group-addon"><i class="fa fa-user"></i></span>
- <input id="txt_Search" type="text" class="form-control" />
- <span class="input-group-addon"><i class="fa fa-search"></i></span>
- </div>
- </div>
and for jquery code
- <script>
- $(document).ready(function () {
-
- $.widget('custom.mcautocomplete', $.ui.autocomplete, {
- _create: function () {
- this._super();
- this.widget().menu("option", "items", "> :not(.ui-widget-header)");
- },
- _renderMenu: function (ul, items) {
- var self = this,
- thead;
- if (this.options.showHeader) {
- table = $('<div class="table-responsive"></div>');
- t1 = $('<table class="table table-hover"></table>').appendTo(table);
- t2 = $('<thead></thead>').appendTo(t1);
- tr1 = $('<tr></tr>').appendTo(t2);
- $.each(this.options.columns, function (index, item) {
- $('<th>' + item.name + '</th>').appendTo(tr1);
- });
- tbody = $('<tbody></tbody>').appendTo(t1);
- ul.append(table);
- }
- $.each(items, function (index, item) {
- self._renderItem(ul, item);
- });
- },
- _renderItem: function (ul, item) {
- var t = '',
- result = '';
- tr2 = $('<tr></tr>').appendTo(tbody).data('ui-autocomplete-item', item);
- $.each(this.options.columns, function (index, column) {
- td1 = $('<td>' + item[column.valueField ? column.valueField : index] + '</td>').appendTo(tr2);
- t += '<td>' + item[column.valueField ? column.valueField : index] + '</td>'
- });
- result = $('<li></li>')
- .data('ui-autocomplete-item', item)
- .append('<a class="mcacAnchor"><tr>' + t + '<div style="clear: both;"></div></tr></a>')
- .appendTo(ul);
- return result;
- }
- });
- $("#txt_Search").mcautocomplete({
- showHeader: true,
- columns: [{
- name: 'NATIONALID',
- width: '150px',
- valueField: 'NATIONALID'
- }, {
- name: 'CustomerName',
- width: '500px',
- valueField: 'CustomerName'
- }, {
- name: 'LastRentDate',
- width: '300px',
- valueField: 'LastRentDate'
- }],
- source: function (request, response) {
- $.ajax({
- url: '<%=ResolveUrl("~/AjaxControls/AjaxOperations.asmx/SearchCustomer") %>',
- data: "{ 'p_CustName': '" + request.term + "'}",
- dataType: "json",
- type: "POST",
- contentType: "application/json",
- success: function (data) {
- response($.map(data.d, function (item) {
- return {
- CustomerID: item.split('||')[0],
- NATIONALID: item.split('||')[1],
- CustomerName: item.split('||')[2],
- ExpirationDate: item.split('||')[3],
- NATIONALITY_DESCR: item.split('||')[4],
- CustomersDebits: item.split('||')[5],
- LastRentDate: item.split('||')[6]
- }
- }))
- },
- error: function (response) {
- alert(response.responseText);
- },
- failure: function (response) {
- alert(response.responseText);
- }
- });
- },
- focus: function (event, ui) {
- $("#txt_Search").val(ui.item.CustomerName);
- return false;
- },
- select: function (e, ui) {
- $("#txt_Search").val(ui.item.CustomerName);
- $("#Customerid").val(ui.item.CustomerID);
- return false;
- },
- minLength: 1
- })
- });
-
- </script>
and this is a print screen for result