Tabulator: Input filtering based on other attributes of the same row?

Created on 9 Feb 2018  路  4Comments  路  Source: olifolkerd/tabulator

Hello!

There's a great example here on how to filter an input for an attribute when the input is an integer value.

{title:"Progress", field:"progress", sorter:"number", align:"left", editor:"input", editor:true,  validator:["min:0", "max:100", "numeric"]},

Is there a specific way to validate the input of one field as a function of the current value of another?

Perhaps even a way to just pass a validator function, that takes the cell as a parameter and returns a function that validates input?

Thanks for your awesome work! I love the project and it's incredibly useful.

Question - Ask On Stack Overflow

All 4 comments

Hey @davidawad

Thanks for your kind words, it is great to hear that Tabulator is appreciated :)

You can do this if you use a custom validator, you can use the getData function on the cell component to retrieve the data object for the row:

//custom validator
var validateOtherColumn = function(cell, value, parameters){
    //cell - the cell component for the edited cell
    //value - the new input value of the cell
    //parameters - the parameters passed in with the validator

    var rowData = cell.getData();

    return rowData.otherColumn % 5; //don't allow values divisible by 5;
}

//column definition
{title:"Progress", field:"progress", sorter:"number", align:"left", editor:"input", editor:true,  validator:validateOtherColumn },

Let me know if that helps,

Cheers

Oli :)

awesome! I'll make a PR to add this to the validator in the examples section on the website

Hey @davidawad

Thanks for the offer, Unfortunately the website is no longer maintained through GitHub, it is now in a private repo because it now references external services.

There is already extensive documentation on validators and custom validators on the website.

I am reluctant to create examples on the site for every single possibility as it will make it very hard for people to find the wood for the trees.

I try and keep the example page showing simple examples of each part of the system.

In a couple of months time i will be launching a case studies section on the website to give people a chance to post their solutions to more unusual problems. It would be great if you would be up for posting your solution then!

Cheers

Oli :)

That sounds great, I'll keep an eye out. Thanks again for all the great work on this tool.

Was this page helpful?
0 / 5 - 0 ratings