Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
P
proyecto-estandar
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Israel Gutierrez Salazar
proyecto-estandar
Commits
79700058
Commit
79700058
authored
Jan 10, 2018
by
Alonso Moreno Postigo
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[EDIT] Arreglado bug del datatable al realizar acciones por fila
parent
0b9ad4fa
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
152 additions
and
129 deletions
+152
-129
PersonaSqlserverDAO.java
src/java/demojsoncrud/sqlserverdao/PersonaSqlserverDAO.java
+35
-35
persona.js
web/js/pages/persona.js
+117
-94
No files found.
src/java/demojsoncrud/sqlserverdao/PersonaSqlserverDAO.java
View file @
79700058
...
@@ -36,15 +36,15 @@ public class PersonaSqlserverDAO implements PersonaDAO {
...
@@ -36,15 +36,15 @@ public class PersonaSqlserverDAO implements PersonaDAO {
try
{
try
{
connection
=
SqlserverDAOFactory
.
obtenerConexion
(
base
);
connection
=
SqlserverDAOFactory
.
obtenerConexion
(
base
);
String
sql
String
sql
=
"select "
=
"select "
+
"a.codigo, "
+
"a.codigo, "
+
"a.dni, "
+
"a.dni, "
+
"a.apellidos, "
+
"a.apellidos, "
+
"a.nombres, "
+
"a.nombres, "
+
"a.edad, "
+
"a.edad, "
+
"a.correo, "
+
"a.correo, "
+
"a.estado "
+
"a.estado "
+
"from persona a "
;
+
"from persona a "
;
psListarPersona
=
connection
.
prepareStatement
(
sql
);
psListarPersona
=
connection
.
prepareStatement
(
sql
);
rsListarPersona
=
psListarPersona
.
executeQuery
();
rsListarPersona
=
psListarPersona
.
executeQuery
();
...
@@ -116,18 +116,18 @@ public class PersonaSqlserverDAO implements PersonaDAO {
...
@@ -116,18 +116,18 @@ public class PersonaSqlserverDAO implements PersonaDAO {
try
{
try
{
connection
=
SqlserverDAOFactory
.
obtenerConexion
(
base
);
connection
=
SqlserverDAOFactory
.
obtenerConexion
(
base
);
String
sql
String
sql
=
"select top "
+
length
+
" "
=
"select top "
+
length
+
" "
+
"a.codigo, "
+
"a.codigo, "
+
"a.dni, "
+
"a.dni, "
+
"a.apellidos, "
+
"a.apellidos, "
+
"a.nombres, "
+
"a.nombres, "
+
"a.edad, "
+
"a.edad, "
+
"a.correo, "
+
"a.correo, "
+
"a.estado "
+
"a.estado "
+
"from persona a "
+
"from persona a "
+
"where a.codigo not in (select top "
+
start
+
" b.codigo from persona b order by 1 desc) "
+
"where a.codigo not in (select top "
+
start
+
" b.codigo from persona b order by 1 desc) "
+
condicion
+
" "
+
condicion
+
" "
+
"order by 1 desc"
;
+
"order by 1 desc"
;
psListarPersona
=
connection
.
prepareStatement
(
sql
);
psListarPersona
=
connection
.
prepareStatement
(
sql
);
rsListarPersona
=
psListarPersona
.
executeQuery
();
rsListarPersona
=
psListarPersona
.
executeQuery
();
...
@@ -205,8 +205,8 @@ public class PersonaSqlserverDAO implements PersonaDAO {
...
@@ -205,8 +205,8 @@ public class PersonaSqlserverDAO implements PersonaDAO {
if
(
resultDni
==
0
)
{
if
(
resultDni
==
0
)
{
String
sql
String
sql
=
"insert into persona (dni, apellidos, nombres, edad, correo, estado) values "
=
"insert into persona (dni, apellidos, nombres, edad, correo, estado) values "
+
"(?,RTRIM(UPPER(?)),RTRIM(UPPER(?)),?,RTRIM(UPPER(?)),1)"
;
+
"(?,RTRIM(UPPER(?)),RTRIM(UPPER(?)),?,RTRIM(UPPER(?)),1)"
;
int
c
=
1
;
//contador para las columnas
int
c
=
1
;
//contador para las columnas
psInsertarPersona
=
connection
.
prepareStatement
(
sql
);
psInsertarPersona
=
connection
.
prepareStatement
(
sql
);
psInsertarPersona
.
setString
(
c
++,
bean
.
getDni
());
psInsertarPersona
.
setString
(
c
++,
bean
.
getDni
());
...
@@ -262,12 +262,12 @@ public class PersonaSqlserverDAO implements PersonaDAO {
...
@@ -262,12 +262,12 @@ public class PersonaSqlserverDAO implements PersonaDAO {
try
{
try
{
connection
=
SqlserverDAOFactory
.
obtenerConexion
(
base
);
connection
=
SqlserverDAOFactory
.
obtenerConexion
(
base
);
String
sql
String
sql
=
"update persona "
=
"update persona "
+
"set apellidos = RTRIM(UPPER(?)), "
+
"set apellidos = RTRIM(UPPER(?)), "
+
"nombres = RTRIM(UPPER(?)), "
+
"nombres = RTRIM(UPPER(?)), "
+
"edad = ?, "
+
"edad = ?, "
+
"correo = RTRIM(UPPER(?)) "
+
"correo = RTRIM(UPPER(?)) "
+
"where codigo = ?"
;
+
"where codigo = ?"
;
psEditarPersona
=
connection
.
prepareStatement
(
sql
);
psEditarPersona
=
connection
.
prepareStatement
(
sql
);
int
q
=
1
;
// CONTADOR PARA LAS COLUMNAS
int
q
=
1
;
// CONTADOR PARA LAS COLUMNAS
...
@@ -320,9 +320,9 @@ public class PersonaSqlserverDAO implements PersonaDAO {
...
@@ -320,9 +320,9 @@ public class PersonaSqlserverDAO implements PersonaDAO {
try
{
try
{
connection
=
SqlserverDAOFactory
.
obtenerConexion
(
base
);
connection
=
SqlserverDAOFactory
.
obtenerConexion
(
base
);
String
sql
String
sql
=
"update persona "
=
"update persona "
+
"set estado = 1 "
+
"set estado = 1 "
+
"where codigo = ?"
;
+
"where codigo = ?"
;
psEditarPersona
=
connection
.
prepareStatement
(
sql
);
psEditarPersona
=
connection
.
prepareStatement
(
sql
);
...
@@ -371,9 +371,9 @@ public class PersonaSqlserverDAO implements PersonaDAO {
...
@@ -371,9 +371,9 @@ public class PersonaSqlserverDAO implements PersonaDAO {
try
{
try
{
connection
=
SqlserverDAOFactory
.
obtenerConexion
(
base
);
connection
=
SqlserverDAOFactory
.
obtenerConexion
(
base
);
String
sql
String
sql
=
"update persona "
=
"update persona "
+
"set estado = 0 "
+
"set estado = 0 "
+
"where codigo = ?"
;
+
"where codigo = ?"
;
psEditarPersona
=
connection
.
prepareStatement
(
sql
);
psEditarPersona
=
connection
.
prepareStatement
(
sql
);
psEditarPersona
.
setString
(
1
,
bean
.
getCodigo
());
psEditarPersona
.
setString
(
1
,
bean
.
getCodigo
());
...
...
web/js/pages/persona.js
View file @
79700058
...
@@ -36,7 +36,8 @@ function listarPersonaTest() {
...
@@ -36,7 +36,8 @@ function listarPersonaTest() {
beforeSend
:
function
(
xhr
)
{
beforeSend
:
function
(
xhr
)
{
// console.log('Antes de...');
// console.log('Antes de...');
},
success
:
function
(
data
,
textStatus
,
jqXHR
)
{
},
success
:
function
(
data
,
textStatus
,
jqXHR
)
{
console
.
log
(
data
);
// console.log(data);
// console.log("listadoTest");
},
complete
:
function
(
jqXHR
,
textStatus
)
{
},
complete
:
function
(
jqXHR
,
textStatus
)
{
// console.log('Siempre ejecutará esta función');
// console.log('Siempre ejecutará esta función');
}
}
...
@@ -87,6 +88,8 @@ function registrarPersona() {
...
@@ -87,6 +88,8 @@ function registrarPersona() {
var
status
=
data
.
status
;
var
status
=
data
.
status
;
if
(
status
)
{
if
(
status
)
{
imprimirAlerta
(
'Correcto!'
,
data
.
message
,
'success'
);
imprimirAlerta
(
'Correcto!'
,
data
.
message
,
'success'
);
var
table
=
$
(
'#tabla_persona'
).
DataTable
();
table
.
ajax
.
reload
();
recargarTabla
();
recargarTabla
();
$
(
'#modal_registrar_persona'
).
modal
(
'hide'
);
$
(
'#modal_registrar_persona'
).
modal
(
'hide'
);
}
else
{
}
else
{
...
@@ -184,6 +187,12 @@ function listarPersona() {
...
@@ -184,6 +187,12 @@ function listarPersona() {
searching
:
false
,
searching
:
false
,
bLengthChange
:
false
,
bLengthChange
:
false
,
bFilter
:
false
,
bFilter
:
false
,
aaSorting
:
[],
ordering
:
false
,
scrollX
:
false
,
ScrollCollapse
:
true
,
columns
:
[
columns
:
[
{
data
:
"item"
},
{
data
:
"item"
},
{
data
:
"dni"
},
{
data
:
"dni"
},
...
@@ -210,110 +219,123 @@ function listarPersona() {
...
@@ -210,110 +219,123 @@ function listarPersona() {
}
}
}
}
],
],
"fnRowCallBack"
:
function
(
row
,
data
,
displayIndex
,
displayIndexFull
)
{
fnRowCallback
:
function
(
row
,
data
,
displayIndex
,
displayIndexFull
)
{
}
});
},
fnPreDrawCallback
:
function
(
settings
)
{
},
fnDrawCallback
:
function
(
settings
)
{
$
(
'#tabla_persona tbody'
).
on
(
'click'
,
'.editarPersona'
,
function
()
{
},
var
data_row
=
tabla_persona
.
row
(
$
(
this
).
parents
(
'tr'
)).
data
();
createdRow
:
function
(
row
,
data
,
dataIndex
)
{
console
.
log
(
data_row
);
codigoPersona
=
''
;
$
(
'#txt_numero_documento_editar'
).
val
(
data_row
.
dni
);
$
(
'#txt_apellidos_editar'
).
val
(
data_row
.
apellidos
);
$
(
'#txt_nombres_editar'
).
val
(
data_row
.
nombres
);
$
(
'#txt_edad_editar'
).
val
(
data_row
.
edad
);
$
(
'#txt_correo_editar'
).
val
(
data_row
.
correo
);
codigoPersona
=
data_row
.
codigo
;
});
$
(
'#tabla_persona tbody'
).
on
(
'click'
,
'.desactivarPersona'
,
function
()
{
var
data_row
=
tabla_persona
.
row
(
$
(
this
).
parents
(
'tr'
)).
data
();
var
json
=
{
codigo
:
data_row
.
codigo
};
swal
({
title
:
"¿Estás seguro?"
,
text
:
"¿Desea desactivar a "
+
data_row
.
apellidos
+
", "
+
data_row
.
nombres
+
" ?"
,
type
:
"warning"
,
showCancelButton
:
true
,
confirmButtonColor
:
"#EF5350"
,
confirmButtonText
:
"Si!"
,
cancelButtonText
:
"No!"
,
closeOnConfirm
:
false
,
closeOnCancel
:
true
},
},
function
(
isConfirm
)
{
initComplete
:
function
(
settings
,
json
)
{
if
(
isConfirm
)
{
$
.
ajax
({
url
:
'../PersonaServlet?accion=desactivarPersona'
,
type
:
'POST'
,
dataType
:
'json'
,
data
:
{
json
:
JSON
.
stringify
(
json
)},
beforeSend
:
function
(
xhr
)
{
},
success
:
function
(
data
,
textStatus
,
jqXHR
)
{
console
.
log
(
data
);
var
status
=
data
.
status
;
if
(
status
)
{
imprimirAlerta
(
'Desactivado!'
,
data_row
.
apellidos
+
', '
+
data_row
.
nombres
+
' fue desactivado con exito!'
,
'success'
);
recargarTabla
();
}
else
{
imprimirAlerta
(
'Error!'
,
data
.
message
,
'error'
);
}
}
});
}
$
(
'#tabla_persona tbody'
).
on
(
'click'
,
'.editarPersona'
,
function
()
{
var
data_row
=
$
(
'#tabla_persona'
).
DataTable
().
row
(
$
(
this
).
parents
(
'tr'
)).
data
();
console
.
log
(
data_row
);
codigoPersona
=
''
;
$
(
'#txt_numero_documento_editar'
).
val
(
data_row
.
dni
);
$
(
'#txt_apellidos_editar'
).
val
(
data_row
.
apellidos
);
$
(
'#txt_nombres_editar'
).
val
(
data_row
.
nombres
);
$
(
'#txt_edad_editar'
).
val
(
data_row
.
edad
);
$
(
'#txt_correo_editar'
).
val
(
data_row
.
correo
);
codigoPersona
=
data_row
.
codigo
;
});
$
(
'#tabla_persona tbody'
).
on
(
'click'
,
'.desactivarPersona'
,
function
()
{
var
data_row
=
$
(
'#tabla_persona'
).
DataTable
().
row
(
$
(
this
).
parents
(
'tr'
)).
data
();
var
json
=
{
codigo
:
data_row
.
codigo
};
alert
(
data_row
.
codigo
);
console
.
log
(
data_row
.
codigo
);
swal
({
title
:
"¿Estás seguro?"
,
text
:
"¿Desea desactivar a "
+
data_row
.
apellidos
+
", "
+
data_row
.
nombres
+
" ?"
,
type
:
"warning"
,
showCancelButton
:
true
,
confirmButtonColor
:
"#EF5350"
,
confirmButtonText
:
"Si!"
,
cancelButtonText
:
"No!"
,
closeOnConfirm
:
false
,
closeOnCancel
:
true
},
function
(
isConfirm
)
{
if
(
isConfirm
)
{
$
.
ajax
({
url
:
'../PersonaServlet?accion=desactivarPersona'
,
type
:
'POST'
,
dataType
:
'json'
,
data
:
{
json
:
JSON
.
stringify
(
json
)},
beforeSend
:
function
(
xhr
)
{
},
success
:
function
(
data
,
textStatus
,
jqXHR
)
{
console
.
log
(
data
);
var
status
=
data
.
status
;
if
(
status
)
{
imprimirAlerta
(
'Desactivado!'
,
data_row
.
apellidos
+
', '
+
data_row
.
nombres
+
' fue desactivado con exito!'
,
'success'
);
recargarTabla
();
}
else
{
imprimirAlerta
(
'Error!'
,
data
.
message
,
'error'
);
}
}
});
}
});
});
}
});
}
});
$
(
'#tabla_persona tbody'
).
on
(
'click'
,
'.activarPersona'
,
function
()
{
});
var
data_row
=
tabla_persona
.
row
(
$
(
this
).
parents
(
'tr'
)).
data
();
var
json
=
{
codigo
:
data_row
.
codigo
};
console
.
log
(
data_row
.
codigo
);
swal
({
title
:
"¿Estás seguro?"
,
text
:
"¿Desea activar a "
+
data_row
.
apellidos
+
", "
+
data_row
.
nombres
+
" ?"
,
type
:
"warning"
,
showCancelButton
:
true
,
confirmButtonColor
:
"#EF5350"
,
confirmButtonText
:
"Si!"
,
cancelButtonText
:
"No!"
,
closeOnConfirm
:
false
,
closeOnCancel
:
true
},
function
(
isConfirm
)
{
if
(
isConfirm
)
{
$
.
ajax
({
url
:
'../PersonaServlet?accion=activarPersona'
,
type
:
'POST'
,
dataType
:
'json'
,
data
:
{
json
:
JSON
.
stringify
(
json
)},
beforeSend
:
function
(
xhr
)
{
},
success
:
function
(
data
,
textStatus
,
jqXHR
)
{
console
.
log
(
data
);
var
status
=
data
.
status
;
if
(
status
)
{
imprimirAlerta
(
'Activado!'
,
data_row
.
apellidos
+
', '
+
data_row
.
nombres
+
' fue activado con exito!'
,
'success'
);
recargarTabla
();
}
else
{
imprimirAlerta
(
'Error!'
,
data
.
message
,
'error'
);
}
$
(
'#tabla_persona tbody'
).
on
(
'click'
,
'.activarPersona'
,
function
()
{
var
data_row
=
$
(
'#tabla_persona'
).
DataTable
().
row
(
$
(
this
).
parents
(
'tr'
)).
data
();
var
json
=
{
codigo
:
data_row
.
codigo
};
console
.
log
(
data_row
.
codigo
);
alert
(
data_row
.
codigo
);
swal
({
title
:
"¿Estás seguro?"
,
text
:
"¿Desea activar a "
+
data_row
.
apellidos
+
", "
+
data_row
.
nombres
+
" ?"
,
type
:
"warning"
,
showCancelButton
:
true
,
confirmButtonColor
:
"#EF5350"
,
confirmButtonText
:
"Si!"
,
cancelButtonText
:
"No!"
,
closeOnConfirm
:
false
,
closeOnCancel
:
true
},
function
(
isConfirm
)
{
if
(
isConfirm
)
{
$
.
ajax
({
url
:
'../PersonaServlet?accion=activarPersona'
,
type
:
'POST'
,
dataType
:
'json'
,
data
:
{
json
:
JSON
.
stringify
(
json
)},
beforeSend
:
function
(
xhr
)
{
},
success
:
function
(
data
,
textStatus
,
jqXHR
)
{
console
.
log
(
data
);
var
status
=
data
.
status
;
if
(
status
)
{
imprimirAlerta
(
'Activado!'
,
data_row
.
apellidos
+
', '
+
data_row
.
nombres
+
' fue activado con exito!'
,
'success'
);
recargarTabla
();
}
else
{
imprimirAlerta
(
'Error!'
,
data
.
message
,
'error'
);
}
}
});
}
});
});
}
}
});
}
});
});
function
initInputs
()
{
function
initInputs
()
{
...
@@ -352,6 +374,7 @@ function imprimirAlerta(title, text, type) {
...
@@ -352,6 +374,7 @@ function imprimirAlerta(title, text, type) {
}
}
function
recargarTabla
()
{
function
recargarTabla
()
{
$
(
'#tabla_persona'
).
DataTable
().
destroy
();
$
(
'#tabla_persona'
).
DataTable
().
destroy
();
listarPersona
();
listarPersona
();
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment