Monday, 20 August 2018

How to lock a w2ui grid row and column?



To lock a column:

w2ui['grid'].columns[col_index].editable=false;


To lock a row:

w2ui['grid'].records[row_index].w2ui.editable=false;

-or-

w2ui['grid'].records[w2ui['grid'].get($(this).attr("recid"),true)].w2ui.editable=false;

-or-

records: [
recid: $(this).attr("ows_ID"),
'w2ui':{
       style: {},
       editable:($(this).attr("ows_columnName")=="Some Value")?false:true
      }
]

To lock the full grid:

w2ui.grid.lock('Loading...', true); //second parameter is for the optional spinner


To lock a particular cell:

There is no out-of-the-box method to support this. However, you can target some of the HTML attributes of the cell to achieve this. You will have to look deep into w2ui js files to understand the working of editable cells.

Something like this may work:

$(window).load(function (){
disableCells ();
}

function disableCells()
{
var rowArr=w2ui['grid'].records;

  $(rowArr).each(function() {
        if($(this).attr("Column Name")=="SomeValue")
        {
//column index = 5
//column name = Column5
$("#"+"grid_grid_data_"+w2ui['grid'].get($(this).attr("recid"),true)+"_5").html("<span>"+$(this).attr("Column5")+"<span>");
}
});
}


If windows.load fails to lock the cells then use the following:

$(window).on('load', function () {
w2alert('Welcome message/instruction.').done(function () {
    disableCells();
});
});

Tuesday, 14 August 2018

[Solved] SharePoint designer workflow lookup for number field is returning 0 for the blank fields.


1. One of the ways is to have a workflow variable and assign it to the lookup value. And then comparing it to 0.


2. Other way is to create a calculated text field in the list and use it instead of the number field in the workflow lookup.

Calculated text field =IF([ColumnName]=0,"-",TEXT([ColumnName],0))


=TEXT([Column],<format>) is used to avoid unwanted zeros after the decimal point. Without this, the final value for the calculated text field would look something like 123.000000000

 <format> is a number format in text format. e.g. 0; 0.0; 0.00; etc.

Friday, 10 August 2018

How to get a cell value from w2ui grid?


var changeArr=w2ui['grid'].getChanges();

$(changeArr).each(function() {

 test = $(w2ui['grid'].get(this.recid)).attr("ColumnName");

//OR

test = w2ui['grid'].getCellValue(w2ui['grid'].get($(this).attr("recid"),true), column_index) ;

});


Tuesday, 7 August 2018

How to add total row at the bottom of a w2ui grid?


$('#grid').w2grid({
    name    : 'grid',
    columns: [               
        { field: 'recid', caption: 'ID', size: '50px' },
        { field: 'lname', caption: 'Last Name', size: '30%' },
        { field: 'fname', caption: 'First Name', size: '30%' },
        { field: 'email', caption: 'Email', size: '40%' },
        { field: 'sdate', caption: 'Start Date', size: '120px' },
        { field: 'sdate', caption: 'End Date', size: '120px' }
    ],
    records: [
        { recid: 1, fname: 'John', lname: 'doe', email: 'vitali@gmail.com', sdate: '1/3/2012' },
        { recid: 2, fname: 'Stuart', lname: 'Motzart', email: 'jdoe@gmail.com', sdate: '2/4/2012' },
        { recid: 3, fname: 'Jin', lname: 'Franson', email: 'jdoe@gmail.com', sdate: '4/23/2012' },
        { recid: 4, fname: 'Susan', lname: 'Ottie', email: 'jdoe@gmail.com', sdate: '5/3/2012' },
        { recid: 5, fname: 'Kelly', lname: 'Silver', email: 'jdoe@gmail.com', sdate: '4/3/2012' },
        { recid: 6, fname: 'Francis', lname: 'Gatos', email: 'vitali@gmail.com', sdate: '2/5/2012' }
    ],
    summary: [
        { recid: 10, fname: 'John', lname: 'doe', email: 'vitali@gmail.com', sdate: '1/3/2012' }
    ]
});


Source: http://w2ui.com/web/docs/1.5/w2grid.summary

Monday, 6 August 2018

How to hide search box in w2ui grid?


show: {
            //...
            toolbarSearch: false,
            searchAll: false,
            toolbarInput: false,
            //...
        },

Friday, 3 August 2018

InfoPath: How apply formatting rule of a date field?


Add the 'Date' field to the form, and change the control to 'Text Box'

Thursday, 2 August 2018

How to add custom buttons in w2ui grid?


toolbar: {
        items: [
            { type: 'break' },
            { type: 'button', id: 'mybutton', caption: 'My other button', img: 'w2ui-icon-check' }
        ],
        onClick: function (event) {
            switch (event.target) {
                case 'mybutton':
                    //business logic here
                    break;
            }
    },

How to execute w2ui delete event without warning message?


w2ui.grid.on('delete', function(event) {
    event.force = true;
    //console.log('No confirmation required');
});

OR

onDelete: function (event) {
        event.force = true;
...
}

Wednesday, 1 August 2018

How to add conditional style in w2ui grid to highlight individual cell?


Add following while preparing records array:

    'w2ui':{style: {
      10: ($(this).attr("ows_Column1")=="Approved")?"background-color: green":"red",
      11: ($(this).attr("ows_Column2")=="Approved")?"background-color: yellow":"",
      }}


To highlight specific header:

<style type="text/css">
td[col="6"].w2ui-head,td[col="7"].w2ui-head {
    border:dashed 2px #0099f8 !important;
    font-weight:bold;
}
</style>