0

I am trying to build a function that will show repeated column item of sharepoint list in selectpicker dropdown having dynamic id . It shows repeated column value instead count as one.

Below is the code of fetch details when page load:

 function getBHData() {
  defPG = $.Deferred();
  $.ajax({
    url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/getbytitle('BudgetMasterList')/items?$select=IsActive,BudgetHolder&$IsActive eq 1",
    method: "GET",
    headers: {
      "Accept": "application/json; odata=nometadata"
    },
    success: function (data) {
      for (var i = 0; i < data.value.length; i++) {
        
          budgetItemsBH.push({
            //ID: data.value[i].EmpIDBH + ',' + data.value[i].BudgetHolder,
            BudgetHolder: data.value[i].BudgetHolder,
            IsActive: data.value[i].IsActive
          });
        }

      defPG.resolve(data);
    },
    error: function (data) {
      defPG.reject(data);
    }
  });
  return defPG.promise();
}

Find Below code for dropdown bind in selectpicker:

function DrpDownBHBind(ID, Flag) {
  var budgetItemsdata = JSON.stringify(budgetItemsBH);
  var result = alasql('SELECT * FROM ? \
   where IsActive=true', [JSON.parse(budgetItemsdata)]);
  var items = result;
  var inputElement = '';
  for (var i = 0; i < items.length; i++) {
    var itemVal = items[i].ID,
        itemText = items[i].BudgetHolder;
        inputElement += '<option value="' + itemVal + '"selected>' + itemText + '</option>';
  }
  $.each(bhName, function (index, item) {
          $('#ddlbudgetHolder' + ID).append(inputElement.val(item).html(item));
  }); 
  //$('#ddlbudgetHolder' + ID).append(inputElement);
  $('#ddlbudgetHolder' + ID).each(function () {
    $('option', this).each(function () {
      if ($(this).val() == '0') {
        $(this).attr('selected', 'selected')
      };
    });
  });

  $('#ddlbudgetHolder' + ID).selectpicker('render');
}

the Image show Budget holder having 7 values

image show 7 Budgetholder column value i need to show 2 values as repeated item count as one in selectpicker dropdown

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.