Skip to main content

Featured

Dhadi Game - An Indian War game

Hi Friends, Today i will introduce an indian traditional board game to android user I am very interested in playing dhadi game with my friends. Now that interest  becomes as an android game Here these are the playing instructions to the dhadi game Dhadi is a traditional indian game with two players.It runs with mind power between 2 players.You can play against your friends Features: Auto Move Suggestions Interesting Graphic View to game Time taken by two players will be shown individually Total movements shows Intresting background sounds and music music and sound on/off feature No permissions are needed to this app. Download the best Dhadi for Android now! https://play.google.com/store/apps/details?id=in.mjtech.daddy

jQuery datatable inline editing with example

To enable editing in the datatable this is the easiest way

first, add this function to get editable data field, This will helps to toggle between editable and normal displaying in datatable

[code language="php"]
function editableValues($val,$id,$col,$tab,$data=""){
if(is_array($data)){
$str= "<div class='vedit' style='width: 100%;' title='double click to edit' id=".$id.">".$val."</div>";

$str.="<select style='display: none;' type='text' class='hedit' id='".$col."' name='".$tab."'>";
foreach ($data as $key => $value) {
$s="";
if($val==$value)
$s="selected";
$str.="<option value='".$key."' $s>".$value."</option>";
}
$str.="</select>";
return $str;
}else{
return "<div class='vedit' style='width: 100%;' title='double click to edit' id=".$id.">".$val."</div><input style='display: none;' type='text' class='hedit' value='".$val."' id='".$col."' name='".$tab."'>";
}
}
[/code]

Now in your ajax data, where you are sending data to the datatable, there you have to send data with above function

In above function 4 arguments are specified, they are for
1st argument ($val) :basic text to display in datatable
2nd argument ($col): the column name in the database table which you have to edit
3rd argument ($tab) :the table where the column exists
4th argument ($data)(optional) :If you want a select dropdown on edit,you have to send this data as key and value(ex:array("0"=>$container->containerid,"1"=>$container->containerid))

to enable editing in datatable some script is needed to edit fields, that is (This needs jQuery)

[code language="javascript"]
$( document). on('keyup',".hedit",function(e) {
if (e.keyCode == 13) {
var hedit=$(this);
update(hedit);
}else if(e.keyCode==27){
var hedit=$(this);
var vedit=hedit.prev();
vedit.toggle();
hedit.toggle();
}
});
$( document). on('change',".hedit",function(e) {
var hedit=$(this);
if($(hedit).is("select")){
update(hedit);
}
});
function update(hedit){
var tab=hedit.attr("name");
var col=hedit.attr("id");
var val=hedit.val();
var vedit=hedit.prev();
var id=vedit.attr("id");
$.ajax({
url:"{{url('admin/dashboard/updateEditable')}}",
method:"POST",
data:{"table":tab,"column":col,"value":val,"id":id},
success:function(data){
if($(hedit).is("select")) {
val = $(hedit).find('option:selected').text();
}
vedit.html(val);
vedit.toggle();
hedit.toggle();
},
error:function(){
alert("Failed to update");
vedit.toggle();
hedit.toggle();
}
});
}
$( document). on('dblclick',".vedit",function() {
$(".hedit").hide();
$(".vedit").show();
$(this).toggle();
var hedit=$(this).next();
hedit.toggle();
});
[/code]

In the above script update(hedit) is an ajax call to save the change in datatable
I think table_name,column_name and update value is enough to edit that record.

If you have any queries or comments on this feel free to comment below...

keep visiting... :)

Comments

Popular Posts