Start Building Professional
Web Apps Today


 
Categories Question details Back To List
Question  posted by Velmurugant on Oct 18, 2009 22:21
open dhtmlx forum
How to check duplicate entry with database as i am using DHtmlx Grid with dataprocessor?

Hi,
I am using DHtmlx Grid to add/edit categories into the database. But i dont want to allow dupicate category name. I am using Dataprocessor to add/update category. How to check the duplicate? If the entered category value already exists in the database, we have to throw error message that says "category already exixts." how to implement this? Please help me.

My code is as follows.


//init grid and set its parameters (this part as always)

     mygrid1 = new dhtmlXGridObject('gridbox1');
     mygrid1.setImagePath("themes/General/css/dhtmlxGrid/imgs/");
     var flds = "Category, Code, Status";
        mygrid1.setHeader(flds);
        mygrid1.attachHeader("#text_filter,#text_filter,#select_filter");
        mygrid1.setInitWidths("590,300,300");
        mygrid1.setColAlign("left,left,left");
        mygrid1.setColTypes("ed,ed,co");
        
        mygrid1.getCombo(2).put('Active',"Active");
mygrid1.getCombo(2).put('De-activated',"De-activated");

        mygrid1.setColumnIds("CategoryName, CategoryCode, Status, Action");
        mygrid1.setSkin("gray");
        mygrid1.setColSorting("str,str,str,str")
        mygrid1.init();
        
     var filePath=GenerateXMLforAdminPath+"&Action=GenerateIncidentIssueTypeXMLforMaster&Edit="+edit+"&Delete="+del;
        
    
     mygrid1.attachEvent("onXLS",function(){ document.body.style.cursor ='wait'; this.entBox.style.cursor='wait'; });
mygrid1.attachEvent("onXLE",function(){ document.body.style.cursor ='default'; this.entBox.style.cursor='default'; });
    
    
     function not_empty(value, id, ind)
{
if (value == "")
mygrid1.setCellTextStyle(id, ind, "background-color:#FF9966;");
return value != "";
}


     var newURL=currentPage+"&mode=saveCategory";
     myDataProcessor = new dataProcessor(newURL);

//lock feed url;
// myDataProcessor.setTransactionMode("POST", true);
//set mode as send-all-by-post;
myDataProcessor.setUpdateMode("on");
myDataProcessor.enableDataNames(true);
myDataProcessor.setVerificator(0, not_empty);
myDataProcessor.setVerificator(1, not_empty);
myDataProcessor.defineAction("success",my_action);

myDataProcessor.attachEvent("onRowMark", function(id)
{
if (this.is_invalid(id) == "invalid")
return false;
return true;
});


         
     myDataProcessor.init(mygrid1);
    
    

     if(document.getElementById('View').value=="1")
{
mygrid1.loadXML(filePath,function(){
    
            mygrid1.forEachRow(function(id){
            //alert(id);
            if (mygrid1.cellById(id,2).getValue()=="Active") mygrid1.setCellTextStyle(id,2,"background-color: #a8ec90");
            else if (mygrid1.cellById(id,2).getValue()=="De-activated") mygrid1.setCellTextStyle(id,2,"background-color: #f6a1a5");
            });
            });
        }
        
        function my_action(node){
         if(node.getAttribute("type")=='success')
         {
         document.getElementById('statusmsg').innerHTML="<font color='green' size='2'>Operation successfull</font>";
        
         }
// alert(node.firstChild.data); // Details
return false;
}
    
     function AddNewRow()
     {
     var autoid=document.getElementById('nextCategoryID').value;
          var newValue=" , ,Active,";
          var WhereToAdd=0;
         mygrid1.addRow(autoid,newValue,WhereToAdd);
         mygrid1.setRowTextStyle(autoid,'border:1px solid #000000 ;');
         document.getElementById('nextCategoryID').value=parseInt(autoid)+1;
     }
         
    function saveCategoryDetails()
     {
     myDataProcessor.sendData();
     }






Thanks,
VelmuruganT
Answer posted by dhxSupport7 on Oct 19, 2009 01:25
You can check if category exists on your server side before saving category to data base. If category already exists you can return response with "error" type. To catch such responses you can use defineAction() dataProcessor's method. Please find more information here http://dhtmlx.com/dhxdocs/doku.php?id=dhtmlxdataprocessor:custom_server_side_responses&s[]=defineaction