Omit certain columns when using autoFill

Omit certain columns when using autoFill

KelvinDingKelvinDing Posts: 11Questions: 4Answers: 0

I have a datatable shown below:

I'm trying to use autoFill to allow users to drag values across the whole row however, I do not want the values to go into the columns that are yellow and have the class "weekend". I have managed to grab the class name of the cells using cells[0][0].cell.node().className on a autoFill event however, I do not know how to stop the values from going into the yellow columns and with the class "weekend"

How do I go about stopping the yellow columns from getting autoFilled?

This question has an accepted answers - jump to answer

Answers

  • colincolin Posts: 15,237Questions: 1Answers: 2,598

    Hi @KelvinDing ,

    You can use autoFill.columns - I think (haven't tried it) you should be able to use:

        autoFill: {
            columns: ':not(.weekend)'
        }
    

    Cheers,

    Colin

  • KelvinDingKelvinDing Posts: 11Questions: 4Answers: 0

    Hi @colin ,

    Tried with your method before. Seems like it's not working.
    Is there a way to do something before the autofill submits the data to the database? Maybe like using .on event?

    Cheers,
    Kelvin

  • KelvinDingKelvinDing Posts: 11Questions: 4Answers: 0

    I have managed to achieve what I want by doing a editor.on('preAutoFill') to filter out the columns with the "publicholiday" class.

    $('#testtable').DataTable().on('preAutoFill', function(e, datatable, cells){
    for(var i =0; i < cells[0].length; i++){
    if(cells[0][i].cell.node().className.includes("weekend")){
    cells[0][i].set = cells[0][i].data;
    }else if (cells[0][i].cell.node().className.includes("publicholiday")){
     cells[0][i].set = cells[0][i].data;
       } } });
    
  • colincolin Posts: 15,237Questions: 1Answers: 2,598
    Answer ✓

    Hi @KelvinDing ,

    I just tried here, and it's working there as expected. There is an oddity, where if you drag over it (from a column on either side) and release, the autofill does still happen. It only affects the initiation of the drag. I've raised a bug for that one, so hopefully it'll be fixed soon.

    Cheers,

    Colin

This discussion has been closed.