0

I added this to my page:

<script type="text/javascript" src="{!URLFOR($Resource.kendoReact, 'kendoReact/kendo-dropdowns-react-wrapper.min.js')}"></script>

To access a static resource of the kendo react script I downloaded.

Then set this up in page:

class MultiSelectContainer extends React.Component {
            constructor(props) {
                super(props);
                console.log('Setting up multiselect', props.data);
                this.dataSource = new kendo.data.DataSource({
                    data: props.data,
                    sort: {
                        field: 'name',
                        dir: 'asc'
                    },
                    group: {
                        field: 'resourceType',
                        dir: 'desc'
                    }
                });
                this.placeholder = 'Filter By People...';
                this.enable = false;
                this.minLength = 3;
                this.enforceMinLength = false;
                this.tagTemplate = '<span class="selected-value" title="#:he.decode(data.name)#" style="color: white;">#:he.decode(data.alias)#</span>';
                this.template = $('#dropDownTemplate').html();
                this.dataTextField = 'searchName';
                this.dataValueField = 'value';
                this.filter = 'contains';
                this.autoClose = false;

                this.onChange = this.onChange.bind(this);
                this.onSelect = this.onSelect.bind(this);
            }

            onSelect = (e) => {
                //Erase what the user has typed after they make a selection
                e.sender.input.val('');
            }

            onChange = (e) => {
                console.log('MultiSelect Changing', e);
                var filteredDataSource = e.sender.dataItems();
                //Get selected pills of user filter multi-select, and set their background colors to specified user color (either bland grey, or user defined color)
                var selectedTags = $('.k-multiselect li.k-button');
                for (var i = 0; i < selectedTags.length; i++) {

                    if (selectedTags[i].parentNode.id == 'user-filter_taglist') {
                        //ownerIdArr.push(value[i]);

                        var tag = $(selectedTags[i]);
                        var item = $(tag.find('span.selected-value'));
                        for (var k = 0; k < filteredDataSource.length; k++) {
                            if (item[0].textContent === he.decode(filteredDataSource[k].alias)) {
                                tag.css({
                                    'background': filteredDataSource[k].tagColor,
                                    'width': '100px',
                                    'height': '30px',
                                    'font-size': '15px',
                                    'overflow': 'hidden',
                                    'text-overflow': 'ellipsis',
                                    'border-radius': '5px'
                                });
                            }
                        }
                    }
                }    
            }

            render() {
                return (
                    <div>
                        <MultiSelect
                            change={this.onChange}
                            select={this.onSelect}
                            dataSource={this.dataSource}
                            placeholder={this.placeholder}
                            value={this.values} />
                    </div>
                );
            }
        }

But I get this: ReferenceError: MultiSelect is not defined at MultiSelectContainer.render.

I am assuming this is how I am bringing in the dropdowns react javascript file. With import, you'd do: import {MultiSelect} from 'blah blah path name';, so MultiSelect would be defined.

Is it possible to bring in the JS file like I did, and establish what MultiSelect is so it is defined, like in the import method?

Tyler Dahle
  • 817
  • 1
  • 8
  • 37
  • The loading of the kendo library script happens before your own react code? You are sure of the path to it? Telerik doesn't offer any sample app code (i.e. Todos app, etc) – uncleoptimus Apr 09 '18 at 23:43

1 Answers1

1

I did kind of figure this out in case anyone might be trying to do something similar... (loading the react scripts in a script tag instead of import).

But, I had to do <window.KendoDropdownsReactWrapper.MultiSelect /> instead of just <MultiSelect />

This should translate to most kendo react scripts you try to load in with a script tag, their components should all be in window.

Tyler Dahle
  • 817
  • 1
  • 8
  • 37
  • Could you elaborate a little on where you got your source from? I have a similar issue here -- https://stackoverflow.com/questions/55593449/include-kendo-react-with-script-tag – Bondolin Apr 09 '19 at 12:56
  • @Bondolin Hopefully I am remembering correctly, but it seems you can only get them through NPM. I think I had to create a folder and NPM install their react stuff, zip it up, then add my folder as a static resource to my Salesforce dev org, where I could access it like I do at the beginning of my question. – Tyler Dahle Apr 09 '19 at 13:54