How do I implement the Dimensions, Weight, and Value column headers that include a small dropdown. and for Dimensions Header, the W, L, and H label in List or Library control?
You can add a dropdown or any other element like this:
var secondColumn = $(fd.control('SPDataTable1').$el).find('th')[1];
//Create and append select list
var selectList = document.createElement("select");
selectList.id = "mySelect";
//Create array of options to be added
var array = ["inch","cm"];
secondColumn.appendChild(selectList);
//Create and append the options
for (var i = 0; i < array.length; i++) {
var option = document.createElement("option");
option.value = array[i];
option.text = array[i];
selectList.appendChild(option);
}
Hi @mnikitina ,
Thanks for answering my questions. I used your approach and tried to implement multiple lists in the headers.
I have another question, please refer to my code below, as I tried to implement lists into different List or Library controls. But the lists are not being successfully implemented, do you know why?
`// adding lists to headers Lenght, Weight, and Value
fd.spRendered(function () {
// list or library 1
var weightCol1 = $(fd.control('SPDataTable1').$el).find('th')[8];
var lengthCol1 = $(fd.control('SPDataTable1').$el).find('th')[5];
var valueCol1 = $(fd.control('SPDataTable1').$el).find('th')[10];
var weightCol2 = $(fd.control('SPDataTable2').$el).find('th')[8];
var lengthCol2 = $(fd.control('SPDataTable2').$el).find('th')[5];
var valueCol2 = $(fd.control('SPDataTable2').$el).find('th')[10];
//Create and append select list
var selectWeight1 = document.createElement("select");
var selectLength1 = document.createElement("select");
var selectValue1 = document.createElement("select");
selectWeight1.id = "mySelectWeight1";
selectLength1.id = "mySelectLength1";
selectValue1.id = "mySelectValue1";
var selectWeight2 = document.createElement("select");
var selectLength2 = document.createElement("select");
var selectValue2 = document.createElement("select");
selectWeight2.id = "mySelectWeight2";
selectLength2.id = "mySelectLength2";
selectValue2.id = "mySelectValue2";
//Create array of options to be added
var arrayLength1 = ["Inch", "Feet", "Meter", "cm"];
var arrayWeight1 = ["LBS", "Kg"];
var arrayValue1 = ["CDN", "EURO", "INR", "US"];
weightCol1.appendChild(selectWeight1);
//weightCol2.appendChild(selectWeight2);
lengthCol1.appendChild(selectLength1);
valueCol1.appendChild(selectValue1);
//Create and append the options
for (var i = 0; i < arrayLength1.length; i++) {
var optionLength1 = document.createElement("option");
optionLength1.value = arrayLength1[i];
optionLength1.text = arrayLength1[i];
selectLength1.appendChild(optionLength1);
selectLength2.appendChild(optionLength1);
}
for (var i = 0; i < arrayWeight1.length; i++) {
var optionWeight1 = document.createElement("option");
optionWeight1.value = arrayWeight1[i];
optionWeight1.text = arrayWeight1[i];
selectWeight1.appendChild(optionWeight1);
}
for (var i = 0; i < arrayValue1.length; i++) {
var optionValue1 = document.createElement("option");
optionValue1.value = arrayValue1[i];
optionValue1.text = arrayValue1[i];
selectValue1.appendChild(optionValue1);
selectValue2.appendChild(optionValue1);
}
});`
You are adding options to the element that doesn't exist. I've updated the code, please try it out:
fd.spRendered(function () {
//columns SPDataTable1
var weightCol1 = $(fd.control('SPDataTable1').$el).find('th')[8];
var lengthCol1 = $(fd.control('SPDataTable1').$el).find('th')[5];
var valueCol1 = $(fd.control('SPDataTable1').$el).find('th')[10];
//Create and append select list
var selectWeight1 = document.createElement("select");
var selectLength1 = document.createElement("select");
var selectValue1 = document.createElement("select");
//add element IDs
selectWeight1.id = "mySelectWeight1";
selectLength1.id = "mySelectLength1";
selectValue1.id = "mySelectValue1";
//Create array of options to be added
var arrayLength1 = ["Inch", "Feet", "Meter", "cm"];
var arrayWeight1 = ["LBS", "Kg"];
var arrayValue1 = ["CDN", "EURO", "INR", "US"];
//add elements to column headers
weightCol1.appendChild(selectWeight1);
lengthCol1.appendChild(selectLength1);
valueCol1.appendChild(selectValue1);
//Create and append the options
for (var i = 0; i < arrayLength1.length; i++) {
var optionLength1 = document.createElement("option");
optionLength1.value = arrayLength1[i];
optionLength1.text = arrayLength1[i];
selectLength1.appendChild(optionLength1);
}
for (var i = 0; i < arrayWeight1.length; i++) {
var optionWeight1 = document.createElement("option");
optionWeight1.value = arrayWeight1[i];
optionWeight1.text = arrayWeight1[i];
selectWeight1.appendChild(optionWeight1);
}
for (var i = 0; i < arrayValue1.length; i++) {
var optionValue1 = document.createElement("option");
optionValue1.value = arrayValue1[i];
optionValue1.text = arrayValue1[i];
selectValue1.appendChild(optionValue1);
}
});
Just to have one quick question on your code above. I realized that changing the dropdown value is not saved when I change the dropdown value located on the headers of the List or Library control and save the change.
for example, refer below to my dropdown value before change:
refer below to my dropdown value after change is saved: