Hi,
am using ig 17.1 version.
I have to create comboeditor with multiselect option in mvc.For that i need to create a custom editorprovider.
How to create new custom editorprovider in mvc. Can you please provide some sample code?
Hello Vasya,I'm using the Infragistics version 2019.1 I used the columnsetting
cs.ColumnSetting().ColumnKey("LocationName").EditorProvider("new $.ig.ComboEditorProviderCustom()").EditorOptions("mode:'dropdown',dataSource:dataSource, textKey: 'Name', valueKey: 'Name',allowCustomValue:true,multiSelection:{enabled:true,showCheckBoxes:true,itemSeparator:','}");
$.ig.ComboEditorProviderCustom = $.ig.EditorProviderCombo.extend({ setSize: function (width, height) { this.editor.element.css({ width: width, height: height }); }, getValue: function () { return this.editor.value(); }, destroy: function () { this.editor.element.remove(); } });
Hello George,
Thank you for providing me your code snippet.
What I noticed is that in the formatter function you are returning an array in case of multiple selected items. By design igGrid does not support arrays. That`s why I modified your function in order to return a string, which is concatenation of all selected values in the drop down editor separated with a space.
Here you will find a small working sample including my modifications for your reference. Please test it on your side and let me know whether it helps you achieve your requirement.
Do not hesitate to contact me if you need any further assistance with this matter.
Thanks for your reply.Everything is working fine except editing.when i edit the combo editor cell value am not able to see the existing selected values.But when i cancel the editing it is showing the existing selected values.
formatter function
function formatProduct(val) { var i, product,c; var n=[]; val=val.toString(); if(val.contains(',')) { val = val.replace(/,\s*$/, ""); c=val.toString().split(','); if(c[0].length>2) { for (i = 1; i < Products.length; i++) { for(var j=0;j<c.length;j++){ product = Products[i]; if (product.txtProductName == c[j]) { } } } n.push(val); } else{ for (i = 1; i < Products.length; i++) { for(var j=0;j<c.length;j++){ product = Products[i]; if (product.txtProductCode == c[j]) { val=Product.txtProductName n.push(val); } } } } return n; } else { for (i = 0; i < Products.length; i++) { product = Products[i]; if (product.txtProductCode == val) { val = product.txtProductName; } return val; } } }
I have primary key as txtProductCode
The reason why an exception is thrown is that the multiple selected values are combined to a string, where different values are separated with the character set to the itemSeparator option of the combo editor, which is ", " by default. This is required because by design igGrid does not support complex values in the underlying data source. To support such scenario a custom implementation is needed for the getValue/setValue methods of the igCombo provider to handle the complex data (in the form of array) passed from the combo multiple selection.
In your scenario if you select PC1 and PC2 they will be represented in the grid as "PC1,PC2" and this is going to be the val that you will be evaluating in the formatter function. My suggestion for applying formatting is separating values in an array, using split method and loop trough them. This will give you an array of substrings which you can itterate.
Please keep in mind that formatter function is going to be applied initially when the grid is loaded and this scenario should also be handled.
Please let me know if you need any further assistance with this matter,
Thank you for your reply.It is working fine.But am having formatter function.when i pass multiple values, while clicking done it is reuturning error.
ex
PC1,PC2=> it should return fridge,washingmachine.
But am getting error like could not find record for the val.
function formatProduct(val) { var i, product; for (i = 0; i < ProductANDJSON.length; i++) { product = ProductANDJSON[i]; if (product.txtProductCode == val) { val = product.txtProductName; } } return val; }