EasyUI Forum
June 24, 2024, 11:46:42 PM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News:
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: checkbox in editable datagrid not checked?  (Read 12281 times)
joe
Newbie
*
Posts: 33


View Profile Email
« on: July 24, 2015, 10:48:47 AM »

One of my column in my editable datagrid uses a checkbox editor:

Code:
<th data-options="field:'mydate',width:60,align:'center',editor:{type:'checkbox',options:{on:getToday(),off:''}}">Status</th>

I was able to check and save the date that the getToday() function return.  However, when I try to reload the saved date back into the datagrid, the checkbox is not checked in edit mode.  The saved date did show on the dategrid when i first load the data but as soon as I try to edit the row, the check box is unchecked and as soon as edit mode stop, the original date was wiped out.

Thanks
Logged
stworthy
Administrator
Hero Member
*****
Posts: 3581


View Profile Email
« Reply #1 on: July 24, 2015, 06:11:10 PM »

How do you define the 'getToday' function? What data type does it return?
Logged
joe
Newbie
*
Posts: 33


View Profile Email
« Reply #2 on: July 24, 2015, 09:30:20 PM »

its a simple function that return today's date.  When I checked the cell, i get today's date displayed and stored to the back end db. It works for today. however on the next day, the cell will be unchecked in edit mode.  the  same behavior occur if I change the stored date to a different date in the db.

Code:
function getToday() {
        var today = new Date();
        today = formatDate(today);

        return today;
    }

function formatDate(date) {
        var y = date.getFullYear();
        var m = date.getMonth() + 1;
        var d = date.getDate();

        if (d < 10) {
            d = '0' + d
        }

        if (m < 10) {
            m = '0' + m
        }

        return y + '.' + m + '.' + d;
    }
Logged
stworthy
Administrator
Hero Member
*****
Posts: 3581


View Profile Email
« Reply #3 on: July 25, 2015, 12:05:51 AM »

Please refer to this example http://jsfiddle.net/02s9gp3L/
Logged
joe
Newbie
*
Posts: 33


View Profile Email
« Reply #4 on: July 25, 2015, 01:07:43 AM »

If you change the "edit1" and "save1" function to accept index 1 and first click on edit and then click on save, you'll see that the checkbox is unchecked automatically. And, if you click save, the date is gone.

Code:
                function edit1(){
$('#dg').datagrid('beginEdit', 1);
}
function save1(){
$('#dg').datagrid('endEdit', 1);
}
Logged
stworthy
Administrator
Hero Member
*****
Posts: 3581


View Profile Email
« Reply #5 on: July 25, 2015, 01:18:53 AM »

That is what the 'checkbox' editor do. The 'checkbox' editor give you two states: 'on' and 'off'. If you uncheck it, the off value will be selected. Please make sure if the 'checkbox' editor fit your requirement.
Logged
joe
Newbie
*
Posts: 33


View Profile Email
« Reply #6 on: July 25, 2015, 01:40:15 AM »

The problem is that I didn't uncheck the checkbox.  The checkbox editor unchecked itself as soon as i click on edit button or it was not checked in the background to begin with.  It does that whenever the loaded date is different from the hard coded "On" date.  

Since my "On" date is a function that always return the current date, the original date gets cleared when the two date is not the same.  this happen every time I edit the row.  Is there a way I can overload the the editor (see code) by passing the row?  that way, i can determine what the original stored date was and return it back to the "on" option instead of always returning the current date.

Code:
editor:{type:'checkbox',options:{on:getToday(row),off:''}
Logged
stworthy
Administrator
Hero Member
*****
Posts: 3581


View Profile Email
« Reply #7 on: July 25, 2015, 06:02:20 PM »

You can modify the options of the 'checkbox' editor before editing a row.
Code:
$('#dg').datagrid({
onBeforeEdit:function(index,row){
var col = $(this).datagrid('getColumnOption', 'status');
col.editor.options.on = row.status;
col.editor.options.off = '';
}
})
Logged
joe
Newbie
*
Posts: 33


View Profile Email
« Reply #8 on: July 25, 2015, 10:22:38 PM »

that did it!  thx!
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines Valid XHTML 1.0! Valid CSS!