Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

Plumsail - DataTable Cascading Dropdowns

fd.spRendered(function() {
    fd.control('DataTable1').$on('edit', function(e) {
        if (e.column.field === 'Category') {
            //pass widget + current Category value
            populateCategories(e.widget, e.model.Category);
        }

        if (e.column.field === 'Product') {
            //pass widget + current Category and Product value
            populateProducts(e.widget, e.model.Category, e.model.Product);
        }
    })

});

function populateCategories(widget, value) {
    //will show as loading
    widget._showBusy();

    sp.web.lists.getByTitle('Categories').items
        .select('ID', 'Title')
        .get()
        .then(function(items) {
            //set options
            widget.setDataSource({
                data: items.map(function(i) { return i.Title })
            });

            //set value if one was select
            widget.value(value);
            //hide loading state
            widget._hideBusy();
        });
}

function populateProducts(widget, parentValue, value) {
    //will show as loading
    widget._showBusy();

    sp.web.lists.getByTitle('Products').items
        .select('ID', 'Title', 'Category/Title')
        .expand('Category')
        .filter("Category/Title eq '" + parentValue + "'")
        .get()
        .then(function(items) {
            widget.setDataSource({
                data: items.map(function(i) { return i.Title })
            });

            //set value if one was select
            widget.value(value);
            //hide loading state
            widget._hideBusy();
        });
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: js delete without changing index 
Javascript :: js draw number in range 
Javascript :: how to add another model into type of model in mongodb schema 
Javascript :: delete all items in an array 
Javascript :: react-folder tree example 
Javascript :: realtime database get by field 
Javascript :: javascript code to run colab in background 
Javascript :: MAP METHOD. IMPORTANT 
Javascript :: pass mltiple valuesthorugh context in react 
Javascript :: javascript Check the answer 
Javascript :: dependent drop down list in jquery 
Javascript :: Setting the default value in the drop down list in AngularJS 
Javascript :: AngularJs: How to interpolate an interpolated string 
Javascript :: Popover AngularJs quickly disappearing 
Javascript :: Calling $http.post in batches and chaining promises 
Javascript :: Calculating state happens to late 
Javascript :: sfc setup vue 3 mounted method - lifecycle methods in sfc 
Javascript :: javascript is nodelist 
Javascript :: PAN SNAP 
Javascript :: send data from a file to frontend nodejs 
Javascript :: filter number from string in javascript 
Javascript :: audio js fast 
Javascript :: javasrccipt loop array 
Javascript :: 120. Triangle - JavaScript Solution With Explantion 
Javascript :: javascript check if a number starts with another number 
Javascript :: empty or remove div span class 
Javascript :: Viewing Your React App On Another Device 
Javascript :: A Method In Class That Accesses A Property 
Javascript :: sweet alert for react 
Javascript :: winston transport file another directory 
ADD CONTENT
Topic
Content
Source link
Name
7+6 =